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

Warning Failed to make bytecode #641

Closed

Description

@vivekp2018

Hi,
Getting a warning while creating executeable
Warning Failed to make bytecode node8-x64 for file /snapshot/node_modules/brotli/build/encode.js

Activity

  1. im-sven commented on Mar 7, 2019

    @im-sven

    Try to run pkg with the --debug flag, for more information.

  2. vivekp2018 commented on Mar 7, 2019

    @vivekp2018
    Author

    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.

  3. alexluoli commented on Mar 13, 2019

    @alexluoli

    Warning Failed to make bytecode node8-x64 for file C:\snapshot\SI-Server\node_modules\brotli\build\encode.js

    same

  4. benfletcher commented on Aug 1, 2019

    @benfletcher

    I'm running into this with Yoga, the Facebook Flexbox cross-environment implementation.

  5. Jozsan commented on Oct 3, 2019

    @Jozsan

    I have the same error, has anybody got a workaround ?

    Warning Failed to make bytecode node12-x64 for file C:\snapshot\<projectName>\node_modules\brotli\build\encode.js
    
  6. maxedon commented on Oct 24, 2019

    @maxedon

    I'm getting this issue as well

    > Warning Failed to make bytecode node12-x64 for file /snapshot/<project-name>/node_modules/brotli/build/encode.js
    
  7. gigouni commented on Jan 27, 2020

    @gigouni

    Hi @emaxedon @Jozsan @benfletcher @alexluoli

    How did you fix it? Did you find a workaround?

    Thanks

  8. Jozsan commented on Jan 27, 2020

    @Jozsan

    Personally, I removed the dependencies that used brotli

  9. gigouni commented on Jan 27, 2020

    @gigouni

    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?

  10. flisboac commented on Jan 29, 2020

    @flisboac

    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.

    My pkg config in package.json is 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):

      [
      {
        "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.

  11. paulgalow commented on Feb 24, 2020

    @paulgalow

    I have run into the same problem:
    > Warning Failed to make bytecode node12-x64 for file /snapshot/<project-name>/node_modules/brotli/build/encode.js

    However, 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.

  12. szabolcsmaj commented on Mar 1, 2020

    @szabolcsmaj

    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
  13. igorklopov commented on Mar 1, 2020

    @igorklopov
    Contributor

    Does you application work after Failed to make bytecode? Because it is intended as Warning - it still lets the application execute well in most cases.

  14. gillez commented on Mar 13, 2020

    @gillez

    @SLOBYYYY said:

    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?

  15. benfletcher commented on Mar 24, 2020

    @benfletcher

    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!

  16. 19 remaining items

  17. hitech95 commented on Nov 21, 2022

    @hitech95

    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.

  18. robertsLando commented on Nov 21, 2022

    @robertsLando
    Contributor

    You need to convert your esm code to cjs and then package it

  19. hitech95 commented on Nov 21, 2022

    @hitech95

    Our code is compiled to cjs via babel. But external dependencies as far I know are out of our control.

  20. robertsLando commented on Nov 21, 2022

    @robertsLando
    Contributor

    Try using ncc but you need an old version because new ones compile everything to esm

  21. hitech95 commented on Nov 21, 2022

    @hitech95

    We use glob array to import some stuff, how does ncc handle this?

  22. robertsLando commented on Nov 21, 2022

    @robertsLando
    Contributor

    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

  23. or185014 commented on Dec 8, 2022

    @or185014

    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

    ...
      "main": "dist-temp/index.js",
      "bin": "dist-temp/index.js",
      "scripts": {
        "build": "tsc && ncc build -o dist",
        "pkg": "pkg ./pkg.config.json -o dist/my.exe",
        ...
      }
    ...
    

    The pkg.config.json used above is essentially a package.json with just the configuration values for the pkg tool needs.

    {
       "main": "dist/index.js",
       "bin": "dist/index.js",
       "pkg": {
          "targets": [
            "node16-win-x64"
          ],
          "assets": [
            "src/images/*"
          ]
        }
    }
    

    I also modified my tsconfig.json to output to a temp folder to separate the transpiled files from the single file ncc produces

    ...
      "compilerOptions": {
        "target": "ES2020",
        "module": "commonjs",
        "strict": true,
        "outDir": "dist-temp",
        "esModuleInterop": true,
      },
    ...
    
  24. rsgilbert commented on Jan 5, 2023

    @rsgilbert

    Thanks everyone, I used @vercel/ncc . My build script is like this:

    "scripts": {
        "test": "jest",
        "start": "node src/index.js",
        "dev": "nodemon src/index.js",
        "build": "ncc build  -o build/lib ./src/index.js && pkg --target node16-win-x64 -o build/MY-API.exe ./build/lib/index.js"
      },
    

    You can also have a build script that first uses babel to compile to commonjs

    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/BANK-API.exe ./build/ncc/lib/index.js && cd build && bestzip BANK-API.zip BANK-API.exe
    

    For the above command, you may need to add a package.json file in the folder build\babel\lib with the value:

    {
        "type": "commonjs"
    }
    
  25. crhistianramirez commented on Mar 9, 2023

    @crhistianramirez

    @rsgilbert small correction --target should be --targets

  26. appurist commented on Mar 9, 2023

    @appurist

    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.

  27. calebeaires commented on Mar 23, 2023

    @calebeaires

    The solution @rsgilbert bring to us helped me, but my pkg failover in another problem. Lua files used by an lib called bull

  28. ThePicYazan commented on Jun 7, 2023

    @ThePicYazan

    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

  29. shirser121 commented on Aug 7, 2023

    @shirser121

    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

    Same here

  30. rsgilbert commented on Aug 7, 2023

    @rsgilbert

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

  31. shirser121 commented on Aug 8, 2023

    @shirser121

    @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.
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions