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

Netlify cli error when importing imagekit npm package in a netlify funcion #4612

Closed
learntheropes opened this issue May 16, 2022 · 3 comments · Fixed by netlify/zip-it-and-ship-it#1119
Assignees
Labels
type: bug code to address defects in shipped code

Comments

@learntheropes
Copy link

learntheropes commented May 16, 2022

Describe the bug

I'm not able to import the imagekit npm package
I tried it on my project and on the netlify nuxt-toolbox
Netlify support confirmed this might be a netlify-cli bug
I get this error:

 > ../../../../../usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/utils/detect_native_module.js:14:32: error: [plugin: external-native-modules] files.some is not a function
    14 │     const hasBinaryFile = files.some((path) => !path.startsWith('!') && (0, path_1.extname)(path) === '.node');
       ╵                                 ^
    at isNativeModule (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/utils/detect_native_module.js:14:33)
    at /usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js:17:158
    at /usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js:35:57
    at callback (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/esbuild/lib/main.js:833:28)
    at handleRequest (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/esbuild/lib/main.js:644:30)

   ../../../../../usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js:26:14: note: This error came from the "onResolve" callback registered here
    26 │         build.onResolve({ filter: packageFilter }, async (args) => {
       ╵               ~~~~~~~~~
    at setup (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js:26:15)
    at handlePlugins (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/esbuild/lib/main.js:746:23)
    at Object.buildOrServe (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/esbuild/lib/main.js:1094:7)
    at /usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/esbuild/lib/main.js:1818:17
    at new Promise (<anonymous>)
    at Object.build (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/esbuild/lib/main.js:1817:14)
    at build (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/esbuild/lib/main.js:1693:51)
    at bundleJsFile (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/bundler.js:60:96)
    at Object.bundle (/usr/local/lib/node_modules/netlify-cli/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/esbuild/index.js:33:150)

   node_modules/imagekit/dist/utils/phash.js:7:49: note: The plugin "external-native-modules" was triggered by this import
     7 │ var hamming_distance_1 = __importDefault(require("hamming-distance"));

Steps to reproduce

run https://github.com/netlify-templates/nuxt-toolbox.git
run cd nuxt-toolbox
run npm install
run npm install --save imagekit
add this line to netlify > functions > joke.js: import ImageKit from 'imagekit'
run netlify dev

Configuration

[build]
  command = "npm run generate"
  functions = "netlify/functions"
  publish = "dist"

[[redirects]]
  from = "/api/*"
  to = "/.netlify/functions/:splat"
  status = 200
  force = true

[functions]
  node_bundler = "esbuild"

Environment

  System:
    OS: Linux 5.15 Ubuntu 22.04 LTS 22.04 LTS (Jammy Jellyfish)
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 819.16 MB / 7.49 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 12.22.9 - /usr/bin/node
    npm: 8.5.1 - /usr/bin/npm
  npmGlobalPackages:
    netlify-cli: 10.3.1
@learntheropes learntheropes added the type: bug code to address defects in shipped code label May 16, 2022
@learntheropes
Copy link
Author

Renaming the file from .js to .mjs does not fix the issue.

@danez
Copy link
Contributor

danez commented Jun 21, 2022

Ref: math-utils/hamming-distance#4

@danez
Copy link
Contributor

danez commented Jun 21, 2022

Thanks for reporting this and sorry for the wait. 💚
We were able to identify the issue and I created a PR (see comment above) in the broken repository.
We also will fix this on our end and will handle invalid package.jsons better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants