web
web copied to clipboard
Could not resolve import '@/utils/string'
I'm using the esbuildPlugin to transpile TS into JS, and am using the tsconfig option, e.g.:
esbuildPlugin({
ts: true,
tsconfig: fileURLToPath(new URL('../../tsconfig.src.json', import.meta.url)),
}),
I've confirmed that this does return the correct file path. It seems, however, that the paths in the tsconfig are not being respected during the compilation, as I get this error when running tests:
Running tests...
Running 2 test files...
transforming file /first.test.ts
first.test.ts:
🚧 Browser logs:
TypeError: Failed to fetch dynamically imported module: http://localhost:8000/first.test.ts?wtr-session-id=d1dh5bc6PE_wVL6xPM-bP
../../packages/browser/second.test.ts:
🚧 Browser logs:
TypeError: Failed to fetch dynamically imported module: http://localhost:8000/packages/browser/second.test.ts?wtr-session-id=hg9x2wsRXit4BnNTNOwjm
🚧 404 network requests:
- packages/browser/second.test.ts?wtr-session-id=hg9x2wsRXit4BnNTNOwjm
❌ Could not import your test module. Check the browser logs or open the browser in debug mode for more information.
Error while transforming first.test.ts: Could not resolve import "@/utils/string".
1 | import chai from "@esm-bundle/chai";
> 2 | import { toKebabCase } from "@/utils/string";
| ^
3 | describe("myFunction", () => {
4 | it("adds two numbers together", () => {
5 | chai.expect(toKebabCase("test to kebab case")).to.equal("test-to-kebab-case");
Chromium: |██████████████████████████████| 2/2 test files | 0 passed, 0 failed
Error while running tests.
Can you create a minimal reproduction of this issue? What does the paths key in the tsconfig.src.json file look like?