Ncc: The value of `module.require` changes after building

Created on 26 May 2019  路  3Comments  路  Source: vercel/ncc

I've recently used ncc to bundle the output from a purescript project and 99% of it worked great! However, one of the libraries I'm using checks the value of module.require as part of determining if it is running in the browser or in node. It appears that ncc changes the value of module.require after building. I've reproduced the issue below:

drew:~/code/example$ cat index.js 
if (module.require) {
  console.log("yes!");
} else {
  console.log("no!");
}
drew:~/code/example$ node index.js 
yes!
drew:~/code/example$ ./node_modules/.bin/ncc build index.js
ncc: Version 0.18.5
ncc: Compiling file index.js
2kB  dist/index.js
2kB  [307ms] - ncc 0.18.5
drew:~/code/example$ node dist/index.js 
no!

Other than this small issue, everything worked fantastic. Thanks so much for this project.

bug committed

Most helpful comment

Glad to hear the project is working well for you!

Yes we should support this case, PR created for the asset loader in https://github.com/zeit/webpack-asset-relocator-loader/pull/42, and let's continue track the merge of that in this issue.

All 3 comments

Glad to hear the project is working well for you!

Yes we should support this case, PR created for the asset loader in https://github.com/zeit/webpack-asset-relocator-loader/pull/42, and let's continue track the merge of that in this issue.

Will this be included in the next release? Thanks!

This should be now fixed in ncc @0.19.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GiladShoham picture GiladShoham  路  3Comments

tomakado picture tomakado  路  4Comments

hrueger picture hrueger  路  4Comments

paulogdm picture paulogdm  路  5Comments

mrmckeb picture mrmckeb  路  5Comments