You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
swc translates the .js import as if it's importing the .ts file, since it matches the .js ending in the final ts emit.
Actual
It crashes:
node:internal/modules/cjs/loader:1147
throw err;
^
Error: Cannot find module './other_file.js'
Require stack:
- /Users/basher/code/ashby/backend/test.ts
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
at Function.Module._load (node:internal/modules/cjs/loader:985:27)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/Users/basher/code/ashby/backend/test.ts:5:60)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._compile (/Users/basher/code/ashby/backend/node_modules/pirates/lib/index.js:117:24)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Object.newLoader [as .ts] (/Users/basher/code/ashby/backend/node_modules/pirates/lib/index.js:121:7)
at Module.load (node:internal/modules/cjs/loader:1207:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/basher/code/ashby/backend/test.ts' ]
}
From this, it looks like swc isn't properly translating the import (to understand that it's importing the local ts file). I understand that this project is very ESM-focused these days, but supporting this would help projects migrate to ESM, since a big first step is switching to .js extensions + node supports .js endings in CommonJS modules.
I was using node 20.11.1, @swc/core 1.4.16, and @swc-node/register 1.9.0
The text was updated successfully, but these errors were encountered:
benasher44
changed the title
Not working for commonjs files that use js extensions in local imports
Not working for commonjs typescript that uses js extensions in local imports
Apr 20, 2024
Repro
Put these files next to each other in the same directory
// other_file.ts
// test.ts
//.swcrc
Run:
SWCRC=true node -r @swc-node/register test.ts
Expect
swc translates the .js import as if it's importing the .ts file, since it matches the .js ending in the final ts emit.
Actual
It crashes:
From this, it looks like swc isn't properly translating the import (to understand that it's importing the local ts file). I understand that this project is very ESM-focused these days, but supporting this would help projects migrate to ESM, since a big first step is switching to .js extensions + node supports .js endings in CommonJS modules.
I was using node 20.11.1, @swc/core 1.4.16, and @swc-node/register 1.9.0
The text was updated successfully, but these errors were encountered: