sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.65k stars 1.92k forks source link

Module Not Found in Build Production w/ Netlify #5337

Closed INTERNAL-ERROR closed 2 years ago

INTERNAL-ERROR commented 2 years ago

Describe the bug

After I updated Svelte to the latest update, I encountered an error that I can't seem to overcome when deploying to Netlify, from code written by Sveltekit in the .netlify foldered.

I have all the latest versions of - Svelte, Sveltekit, SvelteKit Netlify Adapter, and llhttp.

Everytime I try to deploy, I get this error:

7:21:10 AM: ────────────────────────────────────────────────────────────────
7:21:10 AM:   2. Functions bundling                                         
7:21:10 AM: ────────────────────────────────────────────────────────────────
7:21:10 AM: ​
7:21:10 AM: Packaging Functions from .netlify/functions-internal directory:
7:21:10 AM:  - render.js
7:21:10 AM: ​
7:21:11 AM: ​
7:21:11 AM: ────────────────────────────────────────────────────────────────
7:21:11 AM:   Dependencies installation error                               
7:21:11 AM: ────────────────────────────────────────────────────────────────
7:21:11 AM: ​
7:21:11 AM:   Error message
7:21:11 AM:   A Netlify Function failed to require one of its dependencies.
7:21:11 AM:   Please make sure it is present in the site's top-level "package.json".
​
7:21:11 AM:   In file "/opt/build/repo/app/.netlify/functions-internal/render.js"
7:21:11 AM:   Cannot find module './llhttp/llhttp_simd.wasm.js' from '/opt/build/repo/app/.netlify'

I've installed llhttp in the top level package.json. I went digging, and in the file ".netlify/shims.js" on line 3396, it trys: mod = await WebAssembly.compile(Buffer.from(require('./llhttp/llhttp_simd.wasm.js'), 'base64')); This is where the error is coming from, I believe.

My code is hosted on replit: https://replit.com/@AcousticTypewriter911/AudreyTk#app And Github:https://github.com/INTERNAL-ERROR/AudreyTk

Would welcome and advice on how to correct this error. I can "npm run build && npm run preview" without error, this only happens in production.

Reproduction

I have followed every step in how to install Svelte & Sveltekit, and how to run it on Netlify. I'm not sure where I went wrong.

Logs

Full log: 
*7:20:38 AM: Build ready to start
7:20:51 AM: build-image version: 72a309a113b53ef075815b129953617827965e48 (focal)
7:20:51 AM: build-image tag: v4.8.2
7:20:51 AM: buildbot version: 515e5c33287d8b909c004fcf2e460e8645e8c1c6
7:20:51 AM: Fetching cached dependencies
7:20:51 AM: Finished downloading cache in 89.469431ms
7:20:51 AM: Starting to extract cache
7:20:51 AM: Finished extracting cache in 5.440011ms
7:20:51 AM: Finished fetching cache in 95.068862ms
7:20:51 AM: Starting to prepare the repo for build
7:20:52 AM: Preparing Git Reference refs/heads/master
7:20:52 AM: Parsing package.json dependencies
7:20:53 AM: Different build dir detected, going to use the one specified in the Netlify configuration file: 'app' versus 'app/' in the Netlify UI
7:20:53 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'app/build' versus 'build/' in the Netlify UI
7:20:53 AM: Starting build script
7:20:53 AM: Installing dependencies
7:20:53 AM: Python version set to 2.7
7:20:54 AM: v16.15.1 is already installed.
7:20:55 AM: Now using node v16.15.1 (npm v8.11.0)
7:20:55 AM: Started restoring cached build plugins
7:20:55 AM: Finished restoring cached build plugins
7:20:55 AM: Attempting ruby version 2.7.2, read from environment
7:20:56 AM: Using ruby version 2.7.2
7:20:56 AM: Using PHP version 8.0
7:20:56 AM: No npm workspaces detected
7:20:56 AM: Started restoring cached node modules
7:20:56 AM: Finished restoring cached node modules
7:20:57 AM: Installing NPM modules using NPM version 8.11.0
7:20:57 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
7:20:57 AM: npm WARN config location in the cache, and they are managed by
7:20:57 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
7:20:57 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
7:20:57 AM: npm WARN config location in the cache, and they are managed by
7:20:57 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
7:21:00 AM: > app@0.0.1 prepare
7:21:00 AM: > svelte-kit sync
7:21:00 AM: added 130 packages, and audited 131 packages in 3s
7:21:00 AM: 10 packages are looking for funding
7:21:00 AM:   run `npm fund` for details
7:21:00 AM: found 0 vulnerabilities
7:21:00 AM: NPM modules installed
7:21:01 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
7:21:01 AM: npm WARN config location in the cache, and they are managed by
7:21:01 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
7:21:01 AM: Started restoring cached go cache
7:21:01 AM: Finished restoring cached go cache
7:21:01 AM: Installing Go version 1.17 (requested 1.17)
7:21:06 AM: unset GOOS;
7:21:06 AM: unset GOARCH;
7:21:06 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
7:21:06 AM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
7:21:06 AM: go version >&2;
7:21:06 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
7:21:06 AM: go version go1.17 linux/amd64
7:21:06 AM: Installing missing commands
7:21:06 AM: Verify run directory
7:21:08 AM: ​
7:21:08 AM: ────────────────────────────────────────────────────────────────
7:21:08 AM:   Netlify Build                                                 
7:21:08 AM: ────────────────────────────────────────────────────────────────
7:21:08 AM: ​
7:21:08 AM: ❯ Version
7:21:08 AM:   @netlify/build 27.3.0
7:21:08 AM: ​
7:21:08 AM: ❯ Flags
7:21:08 AM:   baseRelDir: true
7:21:08 AM:   buildId: 62bf02b6c21b8c000951f346
7:21:08 AM:   deployId: 62bf02b6c21b8c000951f348
7:21:08 AM: ​
7:21:08 AM: ❯ Current directory
7:21:08 AM:   /opt/build/repo/app
7:21:08 AM: ​
7:21:08 AM: ❯ Config file
7:21:08 AM:   /opt/build/repo/app/netlify.toml
7:21:08 AM: ​
7:21:08 AM: ❯ Context
7:21:08 AM:   production
7:21:08 AM: ​
7:21:08 AM: ────────────────────────────────────────────────────────────────
7:21:08 AM:   1. build.command from netlify.toml                            
7:21:08 AM: ────────────────────────────────────────────────────────────────
7:21:08 AM: ​
7:21:08 AM: $ npm run build
7:21:08 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
7:21:08 AM: npm WARN config location in the cache, and they are managed by
7:21:08 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
7:21:08 AM: > app@0.0.1 build
7:21:08 AM: > svelte-kit build
7:21:09 AM: vite v2.9.13 building for production...
7:21:09 AM: transforming...
7:21:09 AM: ✓ 13 modules transformed.
7:21:09 AM: rendering chunks...
7:21:10 AM:   Client build completed. Wrote 5 chunks and 1 assets
7:21:10 AM:   Building server
7:21:10 AM: .svelte-kit/output/client/_app/immutable/manifest.json                    1.14 KiB
7:21:10 AM: .svelte-kit/output/client/_app/immutable/start-f5f0626d.js                23.04 KiB / gzip: 8.73 KiB
7:21:10 AM: .svelte-kit/output/client/_app/immutable/layout.svelte-8187eef2.js        0.53 KiB / gzip: 0.35 KiB
7:21:10 AM: .svelte-kit/output/client/_app/immutable/error.svelte-61066a60.js         1.56 KiB / gzip: 0.75 KiB
7:21:10 AM: .svelte-kit/output/client/_app/immutable/pages/index.svelte-b63b29a9.js   0.80 KiB / gzip: 0.47 KiB
7:21:10 AM: .svelte-kit/output/client/_app/immutable/chunks/index-c3650d4a.js         6.84 KiB / gzip: 2.79 KiB
7:21:10 AM: vite v2.9.13 building SSR bundle for production...
7:21:10 AM: transforming...
7:21:10 AM: ✓ 11 modules transformed.
7:21:10 AM: Generated an empty chunk: "hooks"
7:21:10 AM: rendering chunks...
7:21:10 AM: .svelte-kit/output/server/manifest.json                        1.09 KiB
7:21:10 AM: .svelte-kit/output/server/index.js                             73.00 KiB
7:21:10 AM: .svelte-kit/output/server/entries/fallbacks/layout.svelte.js   0.24 KiB
7:21:10 AM: .svelte-kit/output/server/entries/fallbacks/error.svelte.js    0.72 KiB
7:21:10 AM: .svelte-kit/output/server/entries/pages/index.svelte.js        0.32 KiB
7:21:10 AM: .svelte-kit/output/server/chunks/index-5f038599.js             2.31 KiB
7:21:10 AM: .svelte-kit/output/server/chunks/hooks-1c45ba0b.js             0.00 KiB
7:21:10 AM:   Prerendering
7:21:10 AM: Run npm run preview to preview your production build locally.
7:21:10 AM: (node:1552) ExperimentalWarning: buffer.Blob is an experimental feature. This feature could change at any time
7:21:10 AM: (Use `node --trace-warnings ...` to show where the warning was created)
7:21:10 AM: 
7:21:10 AM: > Using @sveltejs/adapter-netlify
7:21:10 AM:   Publishing to "build"
7:21:10 AM:   Copying assets...
7:21:10 AM:   Writing custom headers...
7:21:10 AM:   Generating serverless functions...
7:21:10 AM:   Writing redirects...
7:21:10 AM:   ✔ done
7:21:10 AM: ​
7:21:10 AM: (build.command completed in 2.4s)
7:21:10 AM: ​
7:21:10 AM: ────────────────────────────────────────────────────────────────
7:21:10 AM:   2. Functions bundling                                         
7:21:10 AM: ────────────────────────────────────────────────────────────────
7:21:10 AM: ​
7:21:10 AM: Packaging Functions from .netlify/functions-internal directory:
7:21:10 AM:  - render.js
7:21:10 AM: ​
7:21:11 AM: ​
7:21:11 AM: ────────────────────────────────────────────────────────────────
7:21:11 AM:   Dependencies installation error                               
7:21:11 AM: ────────────────────────────────────────────────────────────────
7:21:11 AM: ​
7:21:11 AM:   Error message
7:21:11 AM:   A Netlify Function failed to require one of its dependencies.
7:21:11 AM:   Please make sure it is present in the site's top-level "package.json".
​
7:21:11 AM:   In file "/opt/build/repo/app/.netlify/functions-internal/render.js"
7:21:11 AM:   Cannot find module './llhttp/llhttp_simd.wasm.js' from '/opt/build/repo/app/.netlify'
7:21:11 AM: ​
7:21:11 AM:   Resolved config
7:21:11 AM:   build:
7:21:11 AM:     base: /opt/build/repo/app
7:21:11 AM:     command: npm run build
7:21:11 AM:     commandOrigin: config
7:21:11 AM:     publish: /opt/build/repo/app/build
7:21:11 AM:     publishOrigin: config
7:21:11 AM:   headers:
7:21:11 AM:     - for: /_app/immutable/*
      values:
        cache-control: public, immutable, max-age=31536000
  redirects:
    - from: '*'
      status: 200
      to: /.netlify/functions/render
Caching artifacts
7:21:11 AM: Started saving node modules
7:21:11 AM: Finished saving node modules
7:21:11 AM: Started saving build plugins
7:21:11 AM: Finished saving build plugins
7:21:11 AM: Started saving pip cache
7:21:11 AM: Finished saving pip cache
7:21:11 AM: Started saving emacs cask dependencies
7:21:11 AM: Finished saving emacs cask dependencies
7:21:11 AM: Started saving maven dependencies
7:21:11 AM: Finished saving maven dependencies
7:21:11 AM: Started saving boot dependencies
7:21:11 AM: Finished saving boot dependencies
7:21:11 AM: Started saving rust rustup cache
7:21:11 AM: Finished saving rust rustup cache
7:21:11 AM: Started saving go dependencies
7:21:11 AM: Finished saving go dependencies
7:21:17 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:21:17 AM: Creating deploy upload records
7:21:17 AM: Failing build: Failed to build site
7:21:17 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
7:21:17 AM: Finished processing build request in 25.864000358s*

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 AMD EPYC 7B12
    Memory: 18.46 GB / 62.80 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.13.2 - /nix/store/ra8r42571xvv1m85wanh1ll9mxmp0mwl-nodejs-16.13.2/bin/node
    npm: 8.1.2 - /nix/store/ra8r42571xvv1m85wanh1ll9mxmp0mwl-nodejs-16.13.2/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.53 
    @sveltejs/adapter-netlify: ^1.0.0-next.66 => 1.0.0-next.66 
    @sveltejs/kit: next => 1.0.0-next.357 
    svelte: ^3.44.0 => 3.48.0

Severity

blocking all usage of SvelteKit

Additional Information

I won't be able to use sveltekit if this error is not fixed.

elron commented 2 years ago

Same happens to me. I've posted on Netlify forum as well: https://answers.netlify.com/t/debugging-advice-when-trying-to-deploy-sveltekit-to-netlify-cannot-find-module-llhttp-llhttp-simd-wasm-js-from-opt-build-repo-netlify/70397

codercatdev commented 2 years ago

I’ve just had the same thing happen to me, but fixed the issue by using @sveltejs/adapter-netlify directly (rather than via @sveltejs/adapter-auto) and pinning to the previous version of the adapter.

npm add -D @sveltejs/adapter-netlify@1.0.0-next.65
vqt123 commented 2 years ago

Same here

wipersson commented 2 years ago

I’ve just had the same thing happen to me, but fixed the issue by using @sveltejs/adapter-netlify directly (rather than via @sveltejs/adapter-auto) and pinning to the previous version of the adapter.

npm add -D @sveltejs/adapter-netlify@1.0.0-next.65

I have the exact same issue, tried your fix bit it didn't work for me, I still get the same error. Is it implemented in the same way as in the docs (https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify#installation) or did you do something else?

4RSIM3R commented 2 years ago

Same here

wipersson commented 2 years ago

Just tried building it locally using netlify build and it works fine. Still the same issue when deploying though, seems to be enviroment related.

elron commented 2 years ago

Just tried building it locally using netlify build and it works fine. Still the same issue when deploying though, seems to be enviroment related.

I can't netlify build even in local.

thedittmer commented 2 years ago

I’ve just had the same thing happen to me, but fixed the issue by using @sveltejs/adapter-netlify directly (rather than via @sveltejs/adapter-auto) and pinning to the previous version of the adapter.

npm add -D @sveltejs/adapter-netlify@1.0.0-next.65

This works for me.

yogastama commented 2 years ago

I’ve just had the same thing happen to me, but fixed the issue by using @sveltejs/adapter-netlify directly (rather than via @sveltejs/adapter-auto) and pinning to the previous version of the adapter.

npm add -D @sveltejs/adapter-netlify@1.0.0-next.65

Workss!!

untold-titan commented 2 years ago

I fixed this issue by downgrading to version 65 instead of 66. Then followed the normal Netlify tutorial

INTERNAL-ERROR commented 2 years ago

Yep, downgrading to version 65 worked for me. Soooo, something went wrong in there, and I'll alert the devs. Thanks so much, everyone!

samheyman commented 2 years ago

I managed to get my SvelteKit app to build on Netlify by downgrading @sveltejs/adapter-netlify to version 65 instead of 66 and by using the following netlify.toml:

[build]
  command = "npm run build"
  publish = "build"
  functions = "build/functions/"

[dev]
 command = "svelte-kit dev"

[functions]
  directory = "netlify/functions"
  node_bundler = "esbuild"

But when I try and run the app it crashes with the following error message (in Chrome):

Runtime.ImportModuleError - Error: Cannot find module 'stream/web' Require stack: - /var/task/.netlify/functions-internal/render.js - /var/task/render.js - /var/runtime/UserFunction.js - /var/runtime/Runtime.js - /var/runtime/index.js
brittneypostma commented 2 years ago

Let's reopen this one. I don't see an open issue on it and it is still currently broke on the @next version of adapter-netlify.

brittneypostma commented 2 years ago

Even downgrading is no longer working for me on a new site with the downgraded version of the adapter @sveltejs/adapter-netlify@1.0.0-next.65. Getting error in build:

8:33:47 AM:   Error message
8:33:47 AM:   A Netlify Function failed to require one of its dependencies.
8:33:47 AM:   Please make sure it is present in the site's top-level "package.json".
​
8:33:47 AM:   In file "/opt/build/repo/.netlify/functions-internal/render.js"
8:33:47 AM:   Cannot find module './llhttp/llhttp_simd.wasm.js' from '/opt/build/repo/.netlify'
wipersson commented 2 years ago

@brittneypostma Check your package-lock for references to @sveltejs/adapter-netlify": "1.0.0-next.66". That was the fault in my case I had some lingering references to the latest version of the adapter.

brittneypostma commented 2 years ago

I tried manually changing all instances of it and removing the package-lock completely and still getting an error.

benmccann commented 2 years ago

llhttp is from Undici: https://github.com/sveltejs/kit/pull/5117

I can workaround this by setting edge: true

benmccann commented 2 years ago

@ascorbic I'm stumped on this one. Any ideas why adding Undici to SvelteKit might have broken deploys on Netlify?

ascorbic commented 2 years ago

Hey @benmccann. The require in question is in shims.js, which contains the line:

    mod = await WebAssembly.compile(Buffer.from(require('./llhttp/llhttp_simd.wasm.js'), 'base64'));

That file doesn't exist, so when it tries to bundle the function, it fails. This seems to be an error in the Vite bundling process, because that require is still in the compiled shim file.

benmccann commented 2 years ago

Thank you! I believe the bug was in @rollup/plugin-commonjs. I'm not seeing it locally where the plugin was bumped, but it looks like the last release of the Netlify plugin failed, so people aren't getting the fixed version. I'll ask someone who knows more about releases how we can get a new version out

jdlevish commented 2 years ago

I’ve just had the same thing happen to me, but fixed the issue by using @sveltejs/adapter-netlify directly (rather than via @sveltejs/adapter-auto) and pinning to the previous version of the adapter.

npm add -D @sveltejs/adapter-netlify@1.0.0-next.65

This works for me.

Thanks worked for me, life saver

ascorbic commented 2 years ago

I've just checked and can confirm that the new version fixes it for me!

benmccann commented 2 years ago

great! thank you!!

ghostdevv commented 2 years ago

I am still having issues, related?

image

benmccann commented 2 years ago

That looks like a different issue @ghostdevv. My guess would be that your version of Node is too old

ghostdevv commented 2 years ago

@benmccann I thought that too before I found this issue. I am on node 16? I can also try 18 if netlify supports that

benmccann commented 2 years ago

The minor version often matters as well. You might want to make sure you're on the latest Node 16

ascorbic commented 2 years ago

The default node Lambda runtime on Netlify is currently 14 (though it's changing to 16 on Monday), so you may need to manually set it. Set the env var AWS_LAMBDA_JS_RUNTIME to nodejs16.x and do a new deployment.

ghostdevv commented 2 years ago

@ascorbic That fixed it ty

ascorbic commented 2 years ago

The changed default runtime has now rolled out, so new deploys should be on 16 now unless manually specifying another version.

swyxio commented 2 years ago

sharing for others to find - i also had this issue but a redeploy didnt fix it because i had AWS_LAMBDA_JS_RUNTIME set to nodejs14.x (presumably to force it from when the default was node 12). bumped to node16 and redeployed and it is fine now. feels kinda brittle :shrug: but dont have a better idea how to handle

brittneypostma commented 2 years ago

@sw-yx I think now that Netlify's default is 16, you should be able to remove it completely.

johnkegd commented 2 years ago

If you are seeing this and trying to deploy a svelte app to netlify and none of the above options work. Try to check if you have git config core.ignorecase if it's true try to change it to false with the following command git config core.ignorecase false

this worked for me