zip-it-and-ship-it icon indicating copy to clipboard operation
zip-it-and-ship-it copied to clipboard

Working on netlify dev, not on actual deploy

Open PH4NTOMiki opened this issue 2 years ago • 10 comments

Describe the bug

SvelteKit app when deployed to Netlify returns Dynamic require of "fs" is not supported and sometimes Cannot read property 'default' of undefined for routes that have gray-matter import in them, but the route only uses the text "part" of that library, not fs part of it so there shouldn't be that error. The issue persists for node_bundler = esbuild and without it.

I think it has something to do with how you process node_modules.

logs:

Feb 23, 07:43:09 PM: 24d25a60 ERROR  Error: Dynamic require of "fs" is not supported
Feb 23, 07:43:09 PM: 24d25a60     at __require (file:///var/task/.netlify/functions-internal/render.js:28:9)
Feb 23, 07:43:09 PM: 24d25a60     at node_modules/gray-matter/index.js (file:///var/task/.netlify/functions-internal/render.js:10725:14)
Feb 23, 07:43:09 PM: 24d25a60     at __require2 (file:///var/task/.netlify/functions-internal/render.js:34:44)
Feb 23, 07:43:09 PM: 24d25a60     at .netlify/server/chunks/content-4d53413a.js (file:///var/task/.netlify/functions-internal/render.js:17141:37)
Feb 23, 07:43:09 PM: 24d25a60     at __init (file:///var/task/.netlify/functions-internal/render.js:31:50)
Feb 23, 07:43:09 PM: 24d25a60     at .netlify/server/entries/endpoints/api/listContent.json.js (file:///var/task/.netlify/functions-internal/render.js:17185:5)
Feb 23, 07:43:09 PM: 24d25a60     at __init (file:///var/task/.netlify/functions-internal/render.js:31:50)
Feb 23, 07:43:09 PM: 24d25a60     at file:///var/task/.netlify/functions-internal/render.js:26540:51
Feb 23, 07:43:09 PM: 24d25a60     at async resolve (file:///var/task/.netlify/functions-internal/render.js:26295:83)
Feb 23, 07:43:09 PM: 24d25a60     at async respond (file:///var/task/.netlify/functions-internal/render.js:26246:22)

To Reproduce

Steps to reproduce the behavior:

  1. Run git clone https://github.com/PH4NTOMiki/swyxkit.git
  2. Navigate to the cloned repository
  3. git branch debuggingVersions
  4. Run netlify dev
  5. it's WORKING, but NOT when deployed

Configuration

  • If possible, please copy/paste below your netlify.toml.
# example netlify.toml
[build]
  command = "npm run build"
  publish = "build"

[functions]
  directory = "functions"
  node_bundler = "esbuild"
  external_node_modules = ["mdsvex"]

[build.environment]
  NODE_VERSION = "14"
  ## https://github.com/sveltejs/kit/issues/2687

[[headers]]
  ## https://answers.netlify.com/t/content-type-header-not-working-in-netlify-toml/7718
  for = "/*"
  [headers.values]
    X-Frame-Options = "DENY"
    X-XSS-Protection = "1; mode=block"
    Cache-Control = "public, max-age=4000" 
    # cache just over 1 hour for webpagetest to be happy
    X-Content-Type-Options = "nosniff"
    ## Content-Security-Policy = "default-src 'self'; script-src 'nonce-swyx'; img-src *"
  • Please enter the following command in a terminal and copy/paste its output:
npx envinfo --system --binaries --npmPackages netlify-cli --npmGlobalPackages netlify-cli

System: OS: Linux 5.13 Manjaro Linux CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz Memory: 552.13 MB / 7.65 GB Container: Yes Shell: 5.1.12 - /bin/bash Binaries: Node: 17.2.0 - /usr/local/bin/node npm: 8.5.1 - /usr/bin/npm npmGlobalPackages: netlify-cli: 9.8.0

PH4NTOMiki avatar Feb 24 '22 10:02 PH4NTOMiki

Thanks @PH4NTOMiki, going to move this to the correct repo as it seems related to our bundling logic

erezrokah avatar Feb 24 '22 10:02 erezrokah

Hi @PH4NTOMiki. Can you please confirm:

  1. Are you deploying via the Netlify CLI (i.e. using netlify deploy) or using the CI flow?
  2. If you downgrade to version 9.7.0 of the CLI, does the issue persist?

Thanks!

eduardoboucas avatar Feb 24 '22 11:02 eduardoboucas

Also, can you clarify what routes are giving you that runtime error? I've deployed your reproduction case to https://62176ba95237e4afd8500e35--eduardo-tests.netlify.app/ and I haven't been able to reproduce the error yet.

eduardoboucas avatar Feb 24 '22 11:02 eduardoboucas

  1. Happens on both
  2. Yeah

@eduardoboucas you need to deploy debuggingVersions branch, and route is(one of) /api/listContent.json

PH4NTOMiki avatar Feb 24 '22 11:02 PH4NTOMiki

Thanks for the additional info! We're looking into it and we'll keep this issue up-to-date with any progress.

eduardoboucas avatar Feb 24 '22 13:02 eduardoboucas

ah TIL this is due to Z-I-S-I. source issue here: https://github.com/sveltejs/kit/issues/4079#issuecomment-1049744531

i lack the knowledge to suggest a fix but happy to try out any changes as i was the source of the issue..

swyxio avatar Feb 24 '22 18:02 swyxio

I reported a similar issue here:

https://answers.netlify.com/t/netlify-serverless-typescript-functions-fail-with-dynamic-requires/52379/3

vinh-perfectstorm avatar Feb 24 '22 19:02 vinh-perfectstorm

https://answers.netlify.com/t/netlify-serverless-typescript-functions-fail-with-dynamic-requires/52379/13 reverted to working version

PH4NTOMiki avatar Feb 25 '22 13:02 PH4NTOMiki

Esbuild source issue: https://github.com/evanw/esbuild/issues/1921

PH4NTOMiki avatar Feb 25 '22 18:02 PH4NTOMiki

tagging the latest issue i had with this coming up again today. https://github.com/sveltejs/kit/issues/7839#issuecomment-1328605300 i really dont know the cause but the result is we cannot use esbuild on netlify

swyxio avatar Nov 28 '22 06:11 swyxio