Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot find package 'file-type' #9508

Closed
JustSxm opened this issue May 4, 2023 · 7 comments
Closed

Error: Cannot find package 'file-type' #9508

JustSxm opened this issue May 4, 2023 · 7 comments

Comments

@JustSxm
Copy link

JustSxm commented May 4, 2023

Which package is this bug report for?

discord.js/rest

Issue description

When making a bot in CommonJS, dynamic imports of esm modules fails.

Error: Cannot find package 'file-type' imported from C:\snapshot\Bot\node_modules\@discordjs\rest\dist\index.js
Did you mean to import file-type/index.js?
at new NodeError (node:internal/errors:388:5)
at packageResolve (node:internal/modules/esm/resolve:910:9)
at moduleResolve (node:internal/modules/esm/resolve:959:20)
at defaultResolve (node:internal/modules/esm/resolve:1174:11)
 at ESMLoader.resolve (node:internal/modules/esm/loader:605:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
 at ESMLoader.import (node:internal/modules/esm/loader:404:22)
at importModuleDynamically (node:internal/modules/cjs/loader:1050:29)
at importModuleDynamicallyWrapper (node:internal/vm/module:438:21)
at importModuleDynamically (node:vm:384:46)
  1. Create a common js application
  2. Send a message with a file attached to it
  3. Observe

Will anything be done for this?
Thanks

Code sample

No response

Versions

Discord 14.9.0
Node 18.16.0
Typescript 5.0.3

Issue priority

Low (slightly annoying)

Which partials do you have configured?

Not applicable

Which gateway intents are you subscribing to?

Not applicable

I have tested this issue on a development release

No response

@Jiralite
Copy link
Member

Jiralite commented May 4, 2023

Can you provide a code sample?

@JustSxm
Copy link
Author

JustSxm commented May 4, 2023

Can you provide a code sample?

Not easily, no. but when I look in the compiled code given we see
var getFileType = (0, import_util.lazy)(async () => import("file-type"));

Which does not go through the functions at the top "__toESM" and "__toCommonJS" unlike those for example:

var import_node_process = __toESM(require("process"));
var import_v10 = require("discord-api-types/v10");
var import_undici = require("undici");

It uses import instead of require

Locally it works fine, it's just when I deploy it and package it with vercel/pkg that it stops functioning, and I don't know how to reproduce it without it

@imranbarbhuiya
Copy link
Contributor

imranbarbhuiya commented May 4, 2023

It uses import instead of require

it uses dynamic import to load only if needed.

Locally it works fine, it's just when I deploy it and package it with vercel/pkg that it stops functioning, and I don't know how to reproduce it without it

maybevercel/pkg thinks this package isn't getting used so it doesn't bundle it

@JustSxm
Copy link
Author

JustSxm commented May 4, 2023

  1. npm install
  2. Use a discord token an a channel id in Bot.ts
  3. npm run package
  4. execute the package of your os in exec/
    Sample.zip

@JustSxm
Copy link
Author

JustSxm commented May 4, 2023

It uses import instead of require

it uses dynamic import to load only if needed.

Locally it works fine, it's just when I deploy it and package it with vercel/pkg that it stops functioning, and I don't know how to reproduce it without it

maybevercel/pkg thinks this package isn't getting used so it doesn't bundle it

I made sure to include the whole node_modules as asset to test that out. The problem still occurs. Im pretty sure the package is bundled

@didinele
Copy link
Member

didinele commented May 5, 2023

Sorry, but our bundle is correct and the package correctly works with both cjs and mjs under regular environments, so this sounds like an issue with vercel pkg or the environment that you're deploying to.

@didinele didinele closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2023
@SalSevenSix
Copy link

SalSevenSix commented Jun 17, 2023

This problem occurs with nexe too, so it's not just vercel/pkg
I think discord.js devs should really investigate. Either change to fix or convince vercel/pkg & nexe devs they need to make changes.
Note that v13 works fine for me. Problem is only v14.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants