admin管理员组文章数量:1355072
I'm working on writing a client API wrapper for some internal testing. Essentially it's going to act as a npm package our company can use internally to do API testing (using Playwright's API Request library).
The issue I ran into is it would not work any time I used my "built in paths".
For example here is my tsconfig.json
:
{
"compilerOptions": {
"outDir": "dist",
"module": "CommonJS",
"target": "ES6",
"declaration": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"baseUrl": ".",
"esModuleInterop": true,
"paths": {
"@fixtures/*": ["lib/fixtures/*"],
"@constants/*": ["lib/constants/*"],
}
},
"include": ["lib"],
"exclude": ["node_modules", "dist", "test-results", "tests"]
}
Right now my uppermost root directly looks like this:
lib
-api
--client
---(various client classes.ts)
--baseclient.ts
--index.ts (This is where I am pulling in all my client class files that have API methods)
-constants
-fixtures
...rest of the playwright files
My idea is essentially pulling in all the client class files into that index.ts
, then using that as my wrapper. My package.json
has main
defined as dist/api/index.js
.
This does work, however it only works if I switch my imports from something like:
this:
import someFixture from "@fixtures/cool-fixture/foo-fixture.json"
to this:
import someFixture from "../../fixtures/cool-fixture/foo-fixture.json"
That goes for all the "paths" I've defined. I'm assuming something is wrong with my tsconfig.json
file; these all work fine within Playwright itself, but as soon as TypeScript builds it (using tsc build
) it cannot find any file I've set up with the paths.
本文标签: TypeScript paths not working for built npm packageStack Overflow
版权声明:本文标题:TypeScript paths not working for built npm package - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744027626a2578324.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论