-
Notifications
You must be signed in to change notification settings - Fork 69
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 package.json in path #81
Comments
Hello ! Thanks for reporting. I don't know the NCC compiler, but I'll take a look. My first guess is from the docs:
So maybe I'll try to make time and dig into it, I don't know exactly when, but I'll let you know if I find something. |
Thanks @Kehrlann! I can submit a PR to add this change, but holding off until we understand this problem better... it's too weird |
Hello @elfenheart , tl;dr: we can't help from module-alias, this is a PR for NCC instead ... and even with that, the user experience wouldn't be great. My recommandation is to avoid I've taken a look at this issue. Here are my findings. Basically NCC follows the NCC-generated code without changing module aliasIf you keep it inline, you have the following generated code by NCC: base = candidatePackagePaths[i]
npmPackage = __ncc_wildcard$0(base) Which in turns points to: function __ncc_wildcard$0 (arg) {
if (arg === "/") return __webpack_require__(727);
} and 727 is a description of NCC-generated code with your proposed changeIf you extract it, you have: var x = nodePath.join(base, 'package.json')
npmPackage = require(x) Which is nice, makes it import package.json and makes it not blow up. However ! Why the proposed change is not enough
To verify:
Because the alias failed and you get an empty module instead of the aliased module. The code of the aliased module is not included in So my guess is:
So that means we can't really help from What to do nextSo basically NCC needs to use Webpack's aliasing when building, and you need those aliases to match those declared for module-alias. So that would be a change in NCC, because for now they don't let you use aliases (see their webpack config: https://github.com/zeit/ncc/blob/0ad6971d202ee5896310f65e9aedfd1156184346/src/index.js#L112,L259) I'm keeping this open, maybe I'll update the docs to mention that module-alias does not work with NCC. |
I just looked up the issues and PRs in NCC, and it seems they don't want to expose Webpack internals, including |
Hi @Kehrlann, Thank you so much for the detailed analysis and explanation!! |
Hi,
I'm using module-alias with ncc compiler (https://github.com/zeit/ncc) and seeing weird behavior. If I run the code without the ncc compiler, then it's working fine. However, after ncc compiler, then module-alias is throwing error that it cannot find package.json at some path, even though the path does contain package.json file.
I tried with passing a static path for the module-alias init, and still getting the same error.
After debugging and trying to modify the code of module-alias, I find that if I were to add a temporary variable to join the path first, before the npmPackage require being called, then things will work.
line 171
I'm not really sure why assigning the path to a temporary variable before
require
fixes the problem. Any idea?The text was updated successfully, but these errors were encountered: