Paths not being transformed
After setting up a barebones project, with a minimal tsconfig, the the aliased paths are not properly converted when running the app with ts-node. This is the exact config being used,
{
"include": ["src"],
"compilerOptions": {
// Type Checking
"strict": true,
// Modules
"baseUrl": ".",
"module": "ESNext",
"moduleResolution": "node",
"paths": {
"@foo/*": ["src/foo/*"]
},
// Emit
"noEmit": true,
// Interop Constraints
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
// Language and Environment
"jsx": "react-jsx",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"target": "ESNext",
// Completeness
"skipLibCheck": true
},
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node",
"require": ["tsconfig-paths/register"]
}
}
The error is,
$ pnpm ts-node src/index.ts
/path/node_modules/.pnpm/[email protected]_awa2wsr5thmg3i7jqycphctjfq/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:757
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base));
^
CustomError: Cannot find package '@foo/bar' imported from /path/src/index.ts
The file structure is as follows,
├── node_modules
│ ├── tsconfig-paths -> .pnpm/[email protected]/node_modules/tsconfig-paths
│ ├── ts-node -> .pnpm/[email protected]_awa2wsr5thmg3i7jqycphctjfq/node_modules/ts-node
│ ├── ts-unused-exports -> .pnpm/[email protected][email protected]/node_modules/ts-unused-exports
│ ├── @types
│ │ └── node -> ../.pnpm/@[email protected]/node_modules/@types/node
│ └── typescript -> .pnpm/[email protected]/node_modules/typescript
├── package.json
├── pnpm-lock.yaml
├── README.md
├── src
│ ├── foo
│ │ └── bar.ts
│ └── index.ts
└── tsconfig.json
@aryzing Is the problem solved? I also encountered the same problem
I found the answer here: https://github.com/TypeStrong/ts-node/discussions/1450#discussioncomment-1806115
in your package . json add:
"scripts": {"test": "ts-node -r tsconfig-paths/register src/index.ts" },
src/index.ts is just an example, so replace it with your main file
then start with npm run test
Switched to Bun