swc-node
swc-node copied to clipboard
nothing works 😭
if you set the module in .swcrc
and tsconfig.json
to to commonjs
and remove type
from package.json
, it says it doesn't know what an import
statement is.
[nodemon] starting `swc-node -r tsconfig-paths/register ./lib/index.ts`
/Users/daniel/code/unstoppable-domains-website/shared/src/blockchain/index.ts:1
import type {JsonFragment} from '@ethersproject/abi';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at compileFunction (<anonymous>)
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Module._compile (/Users/daniel/code/unstoppable-domains-website/node_modules/pirates/lib/index.js:136:24)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.newLoader [as .ts] (/Users/daniel/code/unstoppable-domains-website/node_modules/pirates/lib/index.js:141:7)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/daniel/code/unstoppable-domains-website/backend/lib/config/uns/index.ts:1:64)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Module._compile (/Users/daniel/code/unstoppable-domains-website/node_modules/pirates/lib/index.js:136:24)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.newLoader [as .ts] (/Users/daniel/code/unstoppable-domains-website/node_modules/pirates/lib/index.js:141:7)
[nodemon] app crashed - waiting for file changes before starting...
if you set the module in .swcrc
and tsconfig.json
to es2020
, and package.json
to module
it says it doesn't know what a .ts
file is.
[nodemon] starting `node -r @swc-node/register -r tsconfig-paths/register --es-module-specifier-resolution=node ./lib/index lib/index.ts`
(node:37719) ExperimentalWarning: The Node.js specifier resolution in ESM is experimental.
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
TypeError: Invalid module "file:///Users/daniel/code/unstoppable-domains-website/backend/lib/index.ts"
at new NodeError (node:internal/errors:371:5)
at ESMLoader.load (node:internal/modules/esm/loader:324:13)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:230:47)
at link (node:internal/modules/esm/module_job:67:21) {
code: 'ERR_INVALID_MODULE_SPECIFIER'
}
This https://github.com/swc-project/swc-node/pull/643 will resolve your issue
@Brooooooklyn sweet thanks
I have to use ts-node because of this problem, waiting eagerly for the patch 👍