Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Unable to compile app with -r esm #954

Closed
acidos opened this issue Jul 28, 2020 · 5 comments
Closed

Unable to compile app with -r esm #954

acidos opened this issue Jul 28, 2020 · 5 comments

Comments

@acidos
Copy link

acidos commented Jul 28, 2020

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
@hasparus
Copy link

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?

@acidos
Copy link
Author

acidos commented Sep 12, 2020

@hasparus no, I gave up...

@marikaner
Copy link

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).

@SnakeDrak
Copy link
Contributor

SnakeDrak commented Nov 3, 2020

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.

@hipstersmoothie
Copy link
Contributor

closing duplicate of #782

jesec added a commit to vercel/pkg-fetch that referenced this issue May 1, 2022
Production binaries shall NOT take NODE_OPTIONS from end-users.

Only the users (developers who use pkg to package their project) should
have control over the flags via the "bake in" (--options) mechanism.

Bug: vercel/pkg#954, vercel/pkg#989, vercel/pkg#1194, vercel/pkg#1517
jesec added a commit to jesec/pkg-fetch that referenced this issue May 3, 2022
Production binaries shall NOT take NODE_OPTIONS from end-users.

Only the users (developers who use pkg to package their project) should
have control over the flags via the "bake in" (--options) mechanism.

Bug: vercel/pkg#954, vercel/pkg#989, vercel/pkg#1194, vercel/pkg#1517
Hypfer pushed a commit to Hypfer/pkg-fetch that referenced this issue May 7, 2022
Production binaries shall NOT take NODE_OPTIONS from end-users.

Only the users (developers who use pkg to package their project) should
have control over the flags via the "bake in" (--options) mechanism.

Bug: vercel/pkg#954, vercel/pkg#989, vercel/pkg#1194, vercel/pkg#1517
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants