Open alicegherbison opened 6 months ago
I also encountered a similar error. When I use
"imports": {
"#fs": {
"node": "fs",
"default": "./src/fs.ts"
}
}
in the package
A
E:\Dev\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 'fs' imported from E:\Dev\package.json
at packageResolve (E:\Dev\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:757:9)
at resolvePackageTargetString (E:\Dev\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:424:16)
at resolvePackageTarget (E:\Dev\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:464:12)
at resolvePackageTarget (E:\Dev\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:510:26)
at packageImportsResolve (E:\Dev\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:620:26)
at moduleResolve (E:\Dev\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:793:21)
at Object.defaultResolve (E:\Dev\node_modules\ts-node\dist-raw\node-internal-modules-esm-resolve.js:912:11)
at E:\Dev\node_modules\ts-node\src\esm.ts:218:35
at entrypointFallback (E:\Dev\node_modules\ts-node\src\esm.ts:168:34)
at E:\Dev\node_modules\ts-node\src\esm.ts:217:14
[nodemon] app crashed - waiting for file changes before starting...
error will appear.
When I change the value of node under imports #fs to ./src/fs.ts
, it works normally. I think maybe ts-node cannot parse the node built-in module in Subpath imports.
Search Terms
I think this is similar or related to https://github.com/TypeStrong/ts-node/issues/2031 and https://github.com/TypeStrong/ts-node/issues/2023 but not sure.
Expected Behavior
When running mocha and pulling in modules from between packages they should resolve and be found when a test runs.
Actual Behavior
When a test script runs a function that itself imports a variable (or anything) from a another package in the monorepo, the variable is not resolved.
Steps to reproduce the problem
Minimal reproduction
This is a minimal reproduction using the same setup and folder structure for our corporate monorepo. The example functions and tests are basic but illustrate exactly the same concept - https://github.com/alicegherbison/import-error
Specifications
{ "name": "import-error", "packageManager": "yarn@3.6.1", "workspaces": [ "packages/*" ], "dependencies": { "@mdx-js/loader": "^3.0.0", "eslint-mdx": "^3.0.0", "eslint-plugin-mdx": "^3.0.0", "jsdom-global": "^3.0.2", "react": "17.0.2", "react-dom": "17.0.2", "react-redux": "7.2.9", "react-router": "6.20.1", "react-router-dom": "6.20.1", "react-router-hash-link": "^2.4.3", "redux": "4.2.1", "rehype-external-links": "2.0.1", "rehype-react": "7.1.1", "source-map-support": "^0.5.21", "ts-node": "^10.9.2", "tsconfig-paths": "^4.2.0" }, "devDependencies": { "@testing-library/react": "14.1.2", "@types/chai": "4.3.11", "@types/chai-dom": "1.11.3", "@types/mocha": "10.0.6", "@types/node": "20.10.4", "@types/react": "17.0.71", "@types/react-dom": "17.0.25", "@types/react-router-dom": "5.3.3", "@typescript-eslint/eslint-plugin": "6.14.0", "@typescript-eslint/parser": "6.14.0", "chai": "5.0.0", "chai-dom": "1.12.0", "cross-env": "7.0.3", "css-loader": "6.8.1", "css-minimizer-webpack-plugin": "5.0.1", "cssnano": "6.0.1", "eslint": "8.55.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-css-modules": "2.12.0", "eslint-plugin-react": "7.33.2", "eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-storybook": "^0.6.15", "fork-ts-checker-webpack-plugin": "9.0.2", "global-jsdom": "9.2.0", "jsdom": "23.0.1", "lint-staged": "15.2.0", "mocha": "10.2.0", "node-abi": "3.52.0", "node-gyp": "10.0.1", "node-loader": "2.0.0", "npm-run-all": "4.1.5", "postcss": "8.4.32", "postcss-loader": "7.3.3", "postcss-scss": "4.0.9", "prettier": "3.1.1", "sass": "1.69.5", "sass-loader": "13.3.2", "semver": "^7.5.4", "style-loader": "3.3.3", "typescript": "5.3.3", "typescript-plugin-css-modules": "5.0.2", "webpack": "5.74.0", "webpack-bundle-analyzer": "4.10.1", "webpack-cli": "5.1.4", "webpack-dev-server": "4.15.1", "webpack-merge": "5.10.0", "workbox-webpack-plugin": "7.0.0" }, "engines": { "node": ">=16" }, "scripts": { "test": "cross-env TS_NODE_FILES=true TS_NODE_BASEURL=. TS_NODE_PROJECT=tsconfig.json mocha --enable-source-maps" }, "type": "module" }