-
Notifications
You must be signed in to change notification settings - Fork 105
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
Cannot Find Module #157
Comments
+1 |
It looks like you are having the same problem that I'm currently having with this. What seems to be happening is that register.js/**
* Installs a custom module load function that can adhere to paths in tsconfig.
* Returns a function to undo paths registration.
*/
function register(explicitParams) {
// ...
Module._resolveFilename = function (request, _parent) {
var isCoreModule = coreModules.hasOwnProperty(request);
if (!isCoreModule) {
// DEBUG ___________________________
if (request.indexOf('@src') === 0) {
console.log(`_resolveFilename handling '${request}', configLoaderResult =`, configLoaderResult);
}
// DEBUG ^^^^^^^^^^^^^^^^^
var found = matchPath(request);
if (found) {
var modifiedArguments = [found].concat([].slice.call(arguments, 1)); // Passes all arguments. Even those that is not specified above.
// tslint:disable-next-line:no-invalid-this
return originalResolveFilename.apply(this, modifiedArguments);
}
}
// tslint:disable-next-line:no-invalid-this
return originalResolveFilename.apply(this, arguments);
};
return function () {
// Return node's module loading to original state.
Module._resolveFilename = originalResolveFilename;
};
} The output from here was like this ( Failure shown in output
If I change What I did to make it work was replace `register-paths.js`const path = require('path');
const tsConfig = require('./tsconfig.json');
const tsConfigPaths = require('tsconfig-paths');
const baseUrl = tsConfig.compilerOptions.baseUrl || '.';
const outDir = tsConfig.compilerOptions.outDir || '.';
const explicitParams = {
baseUrl: path.resolve(baseUrl, outDir),
paths: tsConfig.compilerOptions.paths,
};
const cleanup = tsConfigPaths.register(explicitParams);
// TODO: clean-up when path registration is no longer needed
//cleanup(); |
You can specify correct main in package.json |
+1 same problem Another solution is defining a custom Then this custom file (let's say it is called
|
I have the same problem, based on the readme, I though setting TS_NODE_BASEURL should be the solution, but this has also no effect for me. |
@JarnoRFB yes, TS_NODE_BASEURL seems useless |
Actually I got it to work now using TS_NODE_BASEURL. I have a layout like
and im my tsconfig.json "compilerOptions": {
"outDir": "dist",
"baseUrl": "src",
"paths": {
"@/*": ["./*"]
},
},
"include": [
"src"
], Now when I put a script in my package.json like so "scripts": {
"myscript": "tsc --module 'CommonJS' && TS_NODE_BASEURL=./dist node -r tsconfig-paths/register dist/myscript.js",
} I can run it with What didn't work before was when I had "baseUrl": "./",
"paths": {
"@/*": ["./src"]
}, |
What you share still doesn't work for me. |
@afonsomatos Forgot to change |
Any official patch for this instead of some hacky workaround? |
Oh nevermind this package looks dead. |
I gave up after a while getting it working in production, using either ts-node or plain node or any other method. I feel I found a nice solution though with using https://www.npmjs.com/package/tscpaths package.json:
Dockerfile:
Hope this helps |
+1 this package is useless I think, time to find a different solution EDIT: This package seems to work good for my use case https://github.com/justkey007/tsc-alias |
I ended up just using native paths with esm |
This package hasn't been updated since May 2019. I got it to work with my setup with some small configuration adjustments (I needed to set the output path to However I suggest that people use the package @lbittner-pdftron mentioned (thanks for the tip!) as it's still being maintained and I got that to work with 0 configuration. Just add |
well, after suffering a few hours, I got a solution You need to add
|
This doesn't work for me |
Same, still seems broken. |
can you try wiith import the module-alias dependency in your entry file |
thanx |
i know this is an old issue, but i recently stumbled onto it myself. Relevant configuration:directory structure:
THE MAIN OFFENDER: {
"imports": {
"#src/*": "./dist/src/*",
"#test/*": "./dist/test/*"
},
}
{
"include": [
"src/**/*",
"test/**/*"
],
"exclude": [
"node_modules/**/*",
"dist/**/*"
],
"compilerOptions": {
"rootDir": ".",
"outDir": "./dist",
"baseUrl": ".",
"paths": {
"#src/*": [ "src/*" ],
"#test/*": [ "test/*" ]
},
}
} Problem synopsis:
Workaround:
{
"imports": {
"#src/*": "./src/*",
"#test/*": "./test/*"
},
}
{
"imports": {
"#src/*": "./src/*",
"#test/*": "./test/*"
},
} Explanation:
I do not know if this workaround is foolproof. I can imagine problems when trying to publish a package with multiple Please leave a like if you found this workaround helpful 🙇🙇🙇🙇 |
i get the similar err when i run the npx tsc --noEmit on the pre_commit file in the husky folder and the problem is i think it doesnt consider the compiler options that we defined on the tsconfig.json and doesnt learn the pthes. any thing will be appreciated , im desperate mode right now |
It seems my module paths do not get resolved correctly when using
node
orts-node
src/index.ts
tsconfig.json
Scripts (I get the same error for both)
Error
The text was updated successfully, but these errors were encountered: