node version 8.11.0
npm version 6.4.1
I keep getting an error that says:
[debug] Cannot resolve ''./nconf/stores/' + store'
C:\Program Files (x86)*\workspace*\node_modules\nconflib\nconf.js
Dynamic require may fail at run time, because the requested file
is unknown at compilation time and not included into executable.
Use a string literal as an argument for 'require', or leave it
as is and specify the resolved file name in 'scripts' option.
this happens for multiple node-modules and when it finally builds the exe, it fails when it tries to call nconf.argv saying that it was not included in the build.
Ive tried multiple things over the past few days, doing complete rebuilds, clearing caches, reimporting the project and i keep running into the same issue.
Any ideas on where to begin, or where to go with this?
You can start using a require.js file to add all the dynamically required files in there and add the file to configuration in package.json.
https://github.com/zeit/pkg#config
this fixed all my problems with dynamic require.
@sharathbaddam thanks for your response.
i havent been able to find any examples that use a requrire.js file or how it is supposed to be organized.
i am assuming that it just has all the specific requires and then is somehow brought into the pkg part of the package.json?
@ambrighter Yes, basically you create a file (require.js - for example) and add all your dynamic requires from the warnings you get when building an executable using pkg as shown below :
require('./node_modules/nconf/lib/nconf.js);
require('./node_modules/some_module/lib/someFile.js);
require('./someLocalFile.js');
Later, add this file name in package.json as shown below :
"pkg": {
"scripts": "require.js"
}
Hope that helps !!
Thanks, @sharathbaddam. I was running into the same "Cannot resolve" issue that @ambrighter was seeing and your solution worked for me. Thanks!
By the way, do you know if the name of the file with the require calls matters? I didn't do much testing, when I changed the name of the require.js file to something else (both the file and in package.json) Pkg seemed to fail to pull in the items in the require file. Once I changed it back to require.js things worked as expected.
But what if I don't know what will the resolved file name be? Like for example I create temporary file with name according to some arbitrary variable that the app holds in code.
Perhaps an option to let the app require dynamic files outside of the binary so that it's not needed to resolve them during compilation could prove useful to some people.
Edit: Nevermind, ignore that. I didn't notice it's already possible. It is documented how to achieve it over here and as long as the file is actually there on the user's filesystem, the warning can be safely ignored.
Hey @sharathbaddam , could you have a look into #831?
I'm having a very similar issue and maybe you can help me out there.
Thanks!
Most helpful comment
@ambrighter Yes, basically you create a file (require.js - for example) and add all your dynamic requires from the warnings you get when building an executable using pkg as shown below :
require('./node_modules/nconf/lib/nconf.js);require('./node_modules/some_module/lib/someFile.js);require('./someLocalFile.js');Later, add this file name in package.json as shown below :
"pkg": { "scripts": "require.js" }Hope that helps !!