-
-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ERR_MODULE_NOT_FOUND
CustomError: Cannot find package
when using paths
#2031
Comments
Seems, this is currently not supported on purpose, see #2023 (comment) |
I am facing similar issue can any one please help me out: #2023 (comment) |
This has done the trick for me: #1450 (comment) |
Does not work in node 21 :/ |
I faced the same issue with Specifications:
tsconfig.json {
"extends": "../../tsconfig.json", // referrence below
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./*"],
}
},
"include": ["**/*.ts", "./server/**/*", "./packages/**/*"],
} package.json {
"name": "backend",
"version": "1.0.0",
"scripts": {
"start:server": "npx tsx watch server/server.ts"
},
"license": "Proprietary and Confidential",
"private": true,
"type": "module",
"dependencies": {
"@fastify/autoload": "^6.0.2",
"@fastify/swagger": "^9.4.0",
"@fastify/swagger-ui": "^5.1.0",
"ajv": "^8.17.1",
"dotenv": "^16.4.5",
"fastify": "^5.1.0",
"fastify-cors": "^6.1.0",
"fastify-plugin": "^5.0.1",
"postgres": "^3.4.5",
"redis": "^4.7.0",
"shared": "workspace:^"
},
"devDependencies": {
"@types/node": "^22.10.1",
"dotenv": "^16.4.5",
"typescript": "^5.6.3"
}
} refereenced root tsconfig.json (using yarn workspaces):{ "compilerOptions": { "lib": ["ES2022"], "baseUrl": ".", "module": "ESNext", "composite": true, "skipLibCheck": true, "allowJs": true, "noEmit": true, "incremental": true, "strict": true, "strictBindCallApply": true, "strictFunctionTypes": true, "strictPropertyInitialization": true, "moduleResolution": "Node", "resolveJsonModule": true, "esModuleInterop": true, "isolatedModules": true, "paths": { "*": [".yarn/sdks/typescript/lib/*"], "@root/*": ["./*"], "@shared/*": ["./packages/shared/*"], }, }, "include": ["./apps/**/*", "./packages/**/*"], "exclude": [ "node_modules" ], "files": [] // Prevent this config from compiling anything directly } So when using import as: import psql from '~/packages/db/connection'; For the miported file: import postgres from 'postgres';
const psql = postgres();
export default psql; The error is inside the backend server container is: node:internal/modules/run_main:122
triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '~' imported from /app/<my_app>/apps/backend/server/server.ts |
@Jazcash Have you figured out how to resolve this issue properly ? |
@Jazcash Same thing, still cannot even imagine how to fix that. Found that the most reliable way from any perspectives for using TypesScript with whatever you need - is to write .d.ts files separately from youre main code, which has to be written is JavaScript, and the connect them together by a |
@MyNameIsNeXTSTEP I straight swapped |
I'm importing another file with
import { test } from "@/stuff"
. If I don't use the@
path alias and instead doimport { test } from "./stuff"
then it works fine. Previously thetsconfig-paths
module has worked fine for me, but in this ESM project it seems to not work. Any ideas that don't require abandoning ESM and going back to CJS?Minimal reproduction
https://codesandbox.io/p/sandbox/fast-dew-p8vcjk?file=%2Ftsconfig.json%3A11%2C27
Specifications
^10.9.1
18.16.0
5.1.3
The text was updated successfully, but these errors were encountered: