You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Got this error when run with --debug flag.brotli npm package is using emscripten c++ compiler to compile c++ code to javascript directly.the encode.js file is generated by emscripten c++ compiler and this file is minified one.Many well known packages like fontkit is using brotli package internally for compression.this pkg is having more than 2 lakh downloads mainly as dependency of other packages.
Will get same error if try to generate binary for fontkit.
For me, the same is happening with a dependency called ky. Not depending on it directly. It seems like it requires either transpilation or Node's experimental module support, because it seems to depend on ES2015's module syntax/system.
I bundle a single index.js file from TypeScript sources using Parcel (with parcel build src/index.ts --target node --out-dir dist/main --out-file index.js --experimental-scope-hoisting).
Targets:
node12-linux-x64
node12-win-x64
It seems like running pkg using package.json-based settings as e.g. pkg . --out-dir dist/exe/ causes this error, somehow.
Here are the last lines of output from the second command (i.e. pkg . --debug):
[
{
"nodeRange": "node12",
"platform": "linux",
"arch": "x64",
"output": "~/<REDACTED>/<REDACTED>/dist/exe-linux",
"forceBuild": false,
"fabricator": {
"nodeRange": "node12",
"platform": "linux",
"arch": "x64",
"forceBuild": false,
"binaryPath": "~/.pkg-cache/v2.6/fetched-v12.13.1-linux-x64"
},
"binaryPath": "~/.pkg-cache/v2.6/fetched-v12.13.1-linux-x64"
},
{
"nodeRange": "node12",
"platform": "win",
"arch": "x64",
"output": "~/<REDACTED>/dist/exe-win.exe",
"forceBuild": false,
"fabricator": {
"nodeRange": "node12",
"platform": "linux",
"arch": "x64",
"forceBuild": false,
"binaryPath": "~/.pkg-cache/v2.6/fetched-v12.13.1-linux-x64"
},
"binaryPath": "~/.pkg-cache/v2.6/fetched-v12.13.1-win-x64"
}
]
/snapshot/<REDACTED>/node_modules/ky/index.js:460
export default createInstance();
^^^^^^
SyntaxError: Unexpected token 'export'
at new Script (vm.js:85:7)
at Socket.<anonymous> ([eval]:18:19)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:182:23)
/snapshot/<REDACTED>/node_modules/ky/index.js:460
export default createInstance();
^^^^^^
SyntaxError: Unexpected token 'export'
at new Script (vm.js:85:7)
at Socket.<anonymous> ([eval]:18:19)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:182:23)
> Warning Failed to make bytecode node12-x64 for file /snapshot/<REDACTED>/node_modules/ky/index.js
C:\snapshot\<REDACTED>\node_modules\ky\index.js:460
export default createInstance();
^^^^^^
SyntaxError: Unexpected token 'export'
at new Script (vm.js:85:7)
at Socket.<anonymous> ([eval]:18:19)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:182:23)
C:\snapshot\<REDACTED>\node_modules\ky\index.js:460
export default createInstance();
^^^^^^
SyntaxError: Unexpected token 'export'
at new Script (vm.js:85:7)
at Socket.<anonymous> ([eval]:18:19)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:182:23)
> Warning Failed to make bytecode node12-x64 for file C:\snapshot\<REDACTED>\node_modules\ky\index.js
Surprisingly, if I run pkg dist/main/index.js --output dist/exe/<REDACTED> --targets node12-linux-x64,node12-win-x64 instead, this bytecode generation failure does not occur.
Reacted by rostikowb, Andrea Valla, Taichi and edmilson-microaitec
What I'm going to write is very weird. I was able to find the part that was causing this by very ugly reverse engineering:
In node_modules/brotli/build/encode.js, go to line 40 and search for function Cb. It should be the last one. It ends with the following part: return g|0. When I replaced this with a simple assignment & return, it stopped the error happening (e.g.: const abcd = g|0; return abcd).
I just hopped on this problem so bear in mind the following:
AFAIK the encode.js is platform dependent so this solution might be completely bad for you (I use debian linux with node v10.16.0)
This might not solve anything, just make the error message disappear
I know it doesn't make any sense
Reacted by Ben Fletcher, gillez, David Meister, RzLiFI, Adorian Doran, Lucas Laborne, Miguel Espinoza, Shrayus Masanam and Separator
In node_modules/brotli/build/encode.js, go to line 40 and search for function Cb. It should be the last one. It ends with the following part: return g|0. When I replaced this with a simple assignment & return, it stopped the error happening (e.g.: const abcd = g|0; return abcd).
I've no idea how you found that, but I just tried the same thing and the warning has disappeared for me too. No idea why and I agree that it might be just hiding the message rather than solving anything.
In answer to the question from @igorklopov, my application seems to work fine after the warning occurs. Does this mean it's not a problem?
I sincerly have no clue as I never used it my own and that's a really specific use case, you should give that a try, there should be a fix to that too someway
I had the same issue as a few others with using latest axios version >= 1.x . I solved it by using ncc (It doesn't look like you need to use an older version I am using 0.36.0 just fine). Here is what my build and pkg scripts look like in my package.json
FYI, based on the very helpful comments above, I was finally able to combine this to produce a pkg deliverable based on ESM code earlier today. I used: esbuild ./main.mjs --bundle --platform=node --outfile=dist/main.cjs --define:import.meta.url=__dirname
followed by: pkg -t node18-win dist\main.cjs
and that produced a main.exe file in the current directory.
I had one top-level await that I then needed to replace with a Promise+then, but that was easy enough.
Reacted by SHA, Ronald Bunk and jaime-sandrea-ciplas
Warning Failed to make bytecode node18-x64 for file C:\snapshot\Best Store\node_modules\discord.js-selfbot-v13\node_modules\axios\lib\axios.js
Warning Failed to make bytecode node18-x64 for file C:\snapshot\Best Store\node_modules\discord.js-selfbot-v13\node_modules\axios\lib\utils.js
Warning Failed to make bytecode node18-x64 for file C:\snapshot\Best Store\node_modules\discord.js-selfbot-v13\node_modules\axios\lib\helpers\bind.js
Warning Failed to make bytecode node18-x64 for file C:\snapshot\Best Store\node_modules\discord.js-selfbot-v13\node_modules\axios\lib\axios.js
Warning Failed to make bytecode node18-x64 for file C:\snapshot\Best Store\node_modules\discord.js-selfbot-v13\node_modules\axios\lib\utils.js
Warning Failed to make bytecode node18-x64 for file C:\snapshot\Best Store\node_modules\discord.js-selfbot-v13\node_modules\axios\lib\helpers\bind.js
@shirser121 hi, make sure your package.json is specifying the project as commonjs. If you're using es modules, then you need to first convert the code into commonjs using babel.
Something like: "scripts": { ..., "build": "babel src -d build/babel/lib && ncc build -o build/ncc/lib build/babel/lib/index.js && pkg --compress GZip --target node16-win-x64 -o build/CORPS-API.exe ./build/ncc/lib/index.js" }
I can share more if we are on the same page.
@shirser121 hi, make sure your package.json is specifying the project as commonjs. If you're using es modules, then you need to first convert the code into commonjs using babel.
Something like: "scripts": { ..., "build": "babel src -d build/babel/lib && ncc build -o build/ncc/lib build/babel/lib/index.js && pkg --compress GZip --target node16-win-x64 -o build/CORPS-API.exe ./build/ncc/lib/index.js" } I can share more if we are on the same page.
I not using typescrip.
I success to do it with ncc.
not i get this error:
Warning Cannot resolve 'filePath'
C:\Users\shir ser\Desktop\Cyber\DEV\Node.js\Battabo Data Extractor\build\lib\index.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.
Activity
im-sven commentedon Mar 7, 2019
Try to run pkg with the
--debugflag, for more information.vivekp2018 commentedon Mar 7, 2019
Hi sven,
Got this error when run with --debug flag.brotli npm package is using emscripten c++ compiler to compile c++ code to javascript directly.the encode.js file is generated by emscripten c++ compiler and this file is minified one.Many well known packages like fontkit is using brotli package internally for compression.this pkg is having more than 2 lakh downloads mainly as dependency of other packages.
Will get same error if try to generate binary for fontkit.
alexluoli commentedon Mar 13, 2019
same
benfletcher commentedon Aug 1, 2019
I'm running into this with Yoga, the Facebook Flexbox cross-environment implementation.
Jozsan commentedon Oct 3, 2019
I have the same error, has anybody got a workaround ?
maxedon commentedon Oct 24, 2019
I'm getting this issue as well
gigouni commentedon Jan 27, 2020
Hi @emaxedon @Jozsan @benfletcher @alexluoli
How did you fix it? Did you find a workaround?
Thanks
Jozsan commentedon Jan 27, 2020
Personally, I removed the dependencies that used brotli
gigouni commentedon Jan 27, 2020
Thanks @Jozsan for your answer
Won't be possible for me. Need to find another solution..
brotliwas the only one failing? Did you know (even after) the difference with the other modules justifying all this mess up?flisboac commentedon Jan 29, 2020
For me, the same is happening with a dependency called ky. Not depending on it directly. It seems like it requires either transpilation or Node's experimental module support, because it seems to depend on ES2015's module syntax/system.
I bundle a single
index.jsfile from TypeScript sources using Parcel (withparcel build src/index.ts --target node --out-dir dist/main --out-file index.js --experimental-scope-hoisting).Targets:
It seems like running
pkgusingpackage.json-based settings as e.g.pkg . --out-dir dist/exe/causes this error, somehow.My
pkgconfig inpackage.jsonis as follows:{ "pkg": { "targets": [ "node12-linux-x64", "node12-win-x64" ] } }Here are the last lines of output from the second command (i.e.
pkg . --debug):Surprisingly, if I run
pkg dist/main/index.js --output dist/exe/<REDACTED> --targets node12-linux-x64,node12-win-x64instead, this bytecode generation failure does not occur.paulgalow commentedon Feb 24, 2020
I have run into the same problem:
> Warning Failed to make bytecode node12-x64 for file /snapshot/<project-name>/node_modules/brotli/build/encode.jsHowever, I was able to compile the same project using nexe. Not much of help for solving the issue at hand, I know. But I thought I'd let you know.
szabolcsmaj commentedon Mar 1, 2020
What I'm going to write is very weird. I was able to find the part that was causing this by very ugly reverse engineering:
In
node_modules/brotli/build/encode.js, go to line 40 and search forfunction Cb. It should be the last one. It ends with the following part:return g|0. When I replaced this with a simple assignment & return, it stopped the error happening (e.g.:const abcd = g|0; return abcd).I just hopped on this problem so bear in mind the following:
encode.jsis platform dependent so this solution might be completely bad for you (I use debian linux with nodev10.16.0)igorklopov commentedon Mar 1, 2020
Does you application work after
Failed to make bytecode? Because it is intended asWarning- it still lets the application execute well in most cases.gillez commentedon Mar 13, 2020
@SLOBYYYY said:
I've no idea how you found that, but I just tried the same thing and the warning has disappeared for me too. No idea why and I agree that it might be just hiding the message rather than solving anything.
In answer to the question from @igorklopov, my application seems to work fine after the warning occurs. Does this mean it's not a problem?
benfletcher commentedon Mar 24, 2020
Does wrapping in parens
return (g|0)also resolve the problem?Is there a strategy you can recommend to resolve these issues with other culprit files @SLOBYYYY ? Thanks!
19 remaining items
hitech95 commentedon Nov 21, 2022
I'm facing similar issues with Axios and yup.
We updated an old codebase to newer dependencies and now pkg dosnt want to work.
And I have no idea where to start.
robertsLando commentedon Nov 21, 2022
You need to convert your esm code to cjs and then package it
hitech95 commentedon Nov 21, 2022
Our code is compiled to cjs via babel. But external dependencies as far I know are out of our control.
robertsLando commentedon Nov 21, 2022
Try using ncc but you need an old version because new ones compile everything to esm
hitech95 commentedon Nov 21, 2022
We use glob array to import some stuff, how does ncc handle this?
robertsLando commentedon Nov 21, 2022
I sincerly have no clue as I never used it my own and that's a really specific use case, you should give that a try, there should be a fix to that too someway
or185014 commentedon Dec 8, 2022
I had the same issue as a few others with using latest axios version >= 1.x . I solved it by using ncc (It doesn't look like you need to use an older version I am using 0.36.0 just fine). Here is what my build and pkg scripts look like in my package.json
The pkg.config.json used above is essentially a package.json with just the configuration values for the pkg tool needs.
I also modified my tsconfig.json to output to a temp folder to separate the transpiled files from the single file ncc produces
rsgilbert commentedon Jan 5, 2023
Thanks everyone, I used @vercel/ncc . My build script is like this:
You can also have a build script that first uses babel to compile to commonjs
For the above command, you may need to add a
package.jsonfile in the folderbuild\babel\libwith the value:crhistianramirez commentedon Mar 9, 2023
@rsgilbert small correction
--targetshould be--targetsappurist commentedon Mar 9, 2023
FYI, based on the very helpful comments above, I was finally able to combine this to produce a pkg deliverable based on ESM code earlier today. I used:
esbuild ./main.mjs --bundle --platform=node --outfile=dist/main.cjs --define:import.meta.url=__dirnamefollowed by:
pkg -t node18-win dist\main.cjsand that produced a
main.exefile in the current directory.I had one top-level
awaitthat I then needed to replace with a Promise+then, but that was easy enough.calebeaires commentedon Mar 23, 2023
The solution @rsgilbert bring to us helped me, but my pkg failover in another problem. Lua files used by an lib called bull
ThePicYazan commentedon Jun 7, 2023
Warning Failed to make bytecode node18-x64 for file C:\snapshot\Best Store\node_modules\discord.js-selfbot-v13\node_modules\axios\lib\axios.js
shirser121 commentedon Aug 7, 2023
Same here
rsgilbert commentedon Aug 7, 2023
@shirser121 hi, make sure your package.json is specifying the project as commonjs. If you're using es modules, then you need to first convert the code into commonjs using babel.
Something like:
"scripts": { ..., "build": "babel src -d build/babel/lib && ncc build -o build/ncc/lib build/babel/lib/index.js && pkg --compress GZip --target node16-win-x64 -o build/CORPS-API.exe ./build/ncc/lib/index.js" }I can share more if we are on the same page.
shirser121 commentedon Aug 8, 2023
I not using typescrip.
I success to do it with ncc.
not i get this error: