web icon indicating copy to clipboard operation
web copied to clipboard

Could not resolve import '@/utils/string'

Open andyjessop opened this issue 2 years ago • 1 comments

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.

andyjessop avatar Jan 10 '24 14:01 andyjessop

Can you create a minimal reproduction of this issue? What does the paths key in the tsconfig.src.json file look like?

koddsson avatar Jan 12 '24 17:01 koddsson