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

building issue in production with some NPM packages #7085

Closed
JinIgarashi opened this issue Sep 29, 2022 · 2 comments
Closed

building issue in production with some NPM packages #7085

JinIgarashi opened this issue Sep 29, 2022 · 2 comments

Comments

@JinIgarashi
Copy link

JinIgarashi commented Sep 29, 2022

Describe the bug

We are trying to migrate our sveltekit from 1.0.0-next.355 to the latest version - 1.0.0-next.504, and adapter-node from 1.0.0-next.78 to 1.0.0-next.95.

yarn run dev and yarn run build -> yarn run preview are successfully done, but when I launch server by nodejs through node build/index.js.

I asked this issue in discord, I got few responses. Someone said there is similar issue when he migrated from esbuild to rollup, and adapter-node also migrated from esbuild since v93.

I think our source code migration is done correctly according to the sveltekit guideline, but I guess there is some building issue by adapter-node or vite with some of NPM packages since adapter-node changed from esbuild to rollup.

Reproduction

I found there are at least two endpoints in our project having building issue in sveltekit. I created a very minimal project with the latest sveltekit version.

Please follow the reproduction procedure in README.md at the following repository,

https://github.com/UNDP-Data/sveltekit-build-test

Furthermore, I created another branch in the repo which has downgraded sveltekit.

https://github.com/UNDP-Data/sveltekit-build-test/tree/downgrade-sveltekit

You can compare both main branch and downgrade-sveltekit branch how the server works in production by using node build

Logs

In our project, the following logs were produced by using `yarn run build -> node build` commands.


ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/Users/j_igarashi/Documents/git/UNDP-Data/geohub/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/j_igarashi/Documents/git/UNDP-Data/geohub/build/server/chunks/variables-e4a6492e.js:126157:25
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:527:24)
    at async Promise.all (index 1)
    at async render_page (file:///Users/j_igarashi/Documents/git/UNDP-Data/geohub/build/server/index.js:2297:19)
    at async resolve (file:///Users/j_igarashi/Documents/git/UNDP-Data/geohub/build/server/index.js:2787:22)
    at async respond (file:///Users/j_igarashi/Documents/git/UNDP-Data/geohub/build/server/index.js:2825:22)
    at async Array.ssr (file:///Users/j_igarashi/Documents/git/UNDP-Data/geohub/build/handler.js:19060:3)

The following log is when I downgraded adapter-node to 1.0.0-next.92.

> Using @sveltejs/adapter-node
✘ [ERROR] Could not resolve "pg-native"

    node_modules/pg/lib/native/client.js:4:21:
      4 │ var Native = require('pg-native')
        ╵                      ~~~~~~~~~~~

  You can mark the path "pg-native" as external to exclude it from the bundle, which will remove
  this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

✘ [ERROR] No loader is configured for ".node" files: node_modules/canvas/build/Release/canvas.node

    node_modules/canvas/lib/bindings.js:3:25:
      3 │ const bindings = require('../build/Release/canvas.node')
        ╵                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error during build:
Error: Build failed with 2 errors:
node_modules/canvas/lib/bindings.js:3:25: ERROR: No loader is configured for ".node" files: node_modules/canvas/build/Release/canvas.node
node_modules/pg/lib/native/client.js:4:21: ERROR: Could not resolve "pg-native"
    at failureErrorWithLog

Other logs for our testing source code are in UNDP-Data/sveltekit-build-test repo's README.

System Info

Our server is running in Azure AppService. The following log was generated in our repository in my laptop.

  System:
    OS: macOS 12.6
    CPU: (8) arm64 Apple M1
    Memory: 107.97 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.9.0 - ~/.nvm/versions/node/v18.9.0/bin/node
    Yarn: 1.22.11 - /opt/homebrew/bin/yarn
    npm: 8.19.1 - ~/.nvm/versions/node/v18.9.0/bin/npm
  Browsers:
    Chrome: 106.0.5249.61
    Firefox: 92.0
    Safari: 16.0
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.78 => 1.0.0-next.96 
    @sveltejs/kit: ^1.0.0-next.355 => 1.0.0-next.504 
    svelte: ^3.48.0 => 3.50.1 

The following log is for our testing repository UNDP-Data/sveltekit-build-test. Also, it was generated in my laptop.

  System:
    OS: macOS 12.6
    CPU: (8) arm64 Apple M1
    Memory: 86.81 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.9.0 - ~/.nvm/versions/node/v18.9.0/bin/node
    Yarn: 1.22.11 - /opt/homebrew/bin/yarn
    npm: 8.19.1 - ~/.nvm/versions/node/v18.9.0/bin/npm
  Browsers:
    Chrome: 106.0.5249.61
    Firefox: 92.0
    Safari: 16.0
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.96 => 1.0.0-next.96 
    @sveltejs/kit: ^1.0.0-next.505 => 1.0.0-next.505 
    svelte: ^3.44.0 => 3.50.1 
    vite: ^3.1.0 => 3.1.4

Severity

blocking an upgrade

Additional Information

Yesterday, I posted the same one in discussion (#7069).

@JinIgarashi
Copy link
Author

I saw this issue #6440, found now bundle everything in devDependencies. I moved @azure/storage-blob and pg to dependencies. Now my test repository works in production.

@benmccann
Copy link
Member

Yes, bundling everything should work. I believe the primary error from running in an unbundled fashion is coming from salesforce/tough-cookie#256

I'm going to close this in favor of that issue since the issue is not in SvelteKit itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants