Pkg: Unable to compile app with -r esm

Created on 28 Jul 2020  路  4Comments  路  Source: vercel/pkg

I am using esm module for running my app. This is how I ran it.

"scripts": {
    "start": "node -r esm src/index.js",

Now when I try to compile my app using pkg with the following line

pkg src/index.js -t node12-macos-x64 --options require=esm

I am getting the following errors for every file

TypeError: require(...).internalModuleStat is not a function
    at internalModuleStat (internal/modules/cjs/loader.js:59:64)
    at stat (internal/modules/cjs/loader.js:143:18)
    at Function.Module._findPath (internal/modules/cjs/loader.js:630:20)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:951:27)
    at Function.Module._load (internal/modules/cjs/loader.js:840:27)
    at Module.require (internal/modules/cjs/loader.js:1024:19)
    at Module._preloadModules (internal/modules/cjs/loader.js:1276:12)
    at loadPreloadModules (internal/bootstrap/pre_execution.js:444:5)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:76:3)
    at internal/bootstrap/pkg.js:7:1
> Warning Failed to make bytecode node12-x64 for file /snapshot/srv/node_modules/accepts/index.js

Most helpful comment

I had the same issue and it was only happening when I ran it from the terminal in VSCode. In a separate terminal it worked. (Changing the shell in VSCode didn't help either).

All 4 comments

Hey @acidos, I'm getting the same error when running hasura metadata export in Hasura CLI.
This is the only place I could find. Have you found a root cause of the problem? Something wrong with Node installation?

@hasparus no, I gave up...

I had the same issue and it was only happening when I ran it from the terminal in VSCode. In a separate terminal it worked. (Changing the shell in VSCode didn't help either).

It seems NODE_OPTIONS is read by the node inside of the pkg, so if you have any special option or bootstrap included on that environment variable, it could generate conflicts with the node inside the pkg (with the debugger, for example).

In my case, that NODE_OPTIPONS was in my particular environment defined by VSCode because I was debugging on that moment. I don't know the reason because VSCode defined the variable in my session, maybe it is related to some particular configuration of the debug options.

I saw some errors related to that: require(...).internalModuleStat is not a function and ERR_INSPECTOR_NOT_AVAILABLE. However, multiple errors could be generated, it depends of each NODE_OPTIONS.

Another example of this, on this issue in _graphql-engine_, solved removing the environment variable.

I don't know if vercel/pkg/@igorklopov want to remove this feature, because it could be useful. However, I will make a PR to include it on the documentation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterjwest picture peterjwest  路  3Comments

jflayhart picture jflayhart  路  4Comments

asaf050 picture asaf050  路  3Comments

Araknos picture Araknos  路  4Comments

ByeongYeon picture ByeongYeon  路  4Comments