Skip to content
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 when works with npm scoped packages #91

Open
yijiasu opened this issue Mar 25, 2020 · 1 comment
Open

Cannot find module when works with npm scoped packages #91

yijiasu opened this issue Mar 25, 2020 · 1 comment

Comments

@yijiasu
Copy link

yijiasu commented Mar 25, 2020

I am getting an issue when using module-alias with some private npm scoped packages.

For example, given we have defined _moduleAliases configuration in package.json, it works well without any private scoped packages (which also has a name starts with @ sign).

If I import any scoped packages (in my case, the name is @org/utility), we will run into a issue like this:

Error: Cannot find module 'org/utility'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._resolveFilename (/Users/***/node_modules/module-alias/index.js:49:29)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/***/dist/utils/ccd.js:14:25)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

It looks like module-alias try to resolve this package as an alias definition while actually it's not. If I manually require package without module-alias hooked, everything works well again.

@Kehrlann
Copy link
Collaborator

Hey @yijiasu , thanks for reporting !

Not sure exactly how private scoped packages work, but I'm not sure the problem is that module-alias is trying to load @org/utility as an alias. Unless you have @org as an alias as well, which might conflict. Using @ for aliasing is just an example, you could use $$$ instead, it would make no difference to module-alias.

Would you mind sharing your package.json ? Even better would be a git repo with everything needed to reproduce the problem.
Also, which version of node are you using ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants