vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.33k stars 1.02k forks source link

Failed to make bytecode for multiple files #1905

Closed Default-01 closed 1 year ago

Default-01 commented 1 year ago

What version of pkg are you using?

latest

What version of Node.js are you using?

18.7

What operating system are you using?

Windows 11

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

any

Describe the Bug

When i run pkg -t node16 index.js i get the following warnings:

> Warning Failed to make bytecode node16-x64 for file C:\snapshot\DBD-Advanced-Ticket-Bot\node_modules\file-type\index.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\DBD-Advanced-Ticket-Bot\node_modules\file-type\core.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\DBD-Advanced-Ticket-Bot\node_modules\file-type\supported.js
> Warning Failed to make bytecode node16-x64 for file C:\snapshot\DBD-Advanced-Ticket-Bot\node_modules\file-type\util.js

Expected Behavior

Should compile properly

To Reproduce

run pkg -t node16 index.js with the latest version of Discord.j@14.9.0 and you get this error.

fcastilloec commented 1 year ago

I'm experiencing the same on Ubuntu 22.04 and node 16. When debugging, I see that the errors happen when a package uses import. I saw this multiple times on the output, when using axios:

function (exports, require, module, __filename, __dirname) { import axios from './lib/axios.js';
                                                              ^^^^^^

SyntaxError: Cannot use import statement outside a module
    at new Script (node:vm:101:7)
    at Socket.<anonymous> ([eval]:18:19)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
nadeemahmad commented 1 year ago

@fcastilloec I am running into a similar issue as above. Do you have any recommendations on how to fix the import issue?

kuema commented 1 year ago

As a workaround, you can include the files in question as assets. The warnings will still be present at build time, but at least you have the files included. They load properly at runtime, just tested it with the axios package.

   "assets": [
      "node_modules/axios/**"
    ]
Sidewinder1138 commented 1 year ago

I'm having the same issue, running on Windows 11, Node 18. I think the paths are wrong, in your example there is: C:\snapshot\DBD-Advanced-Ticket-Bot...

That C:\snapshot doesn't seem right, and it's doing that for me as well.

Sidewinder1138 commented 1 year ago

Update: I saw in another issue that ESM (import) isn't supported, which I am definitely using, will try with CommonJS instead and see if that works.

It might be good if "pkg" could spit out an error message when it seems ESM modules? (until they are supported of course)

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] commented 1 year ago

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.