question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@sveltejs/adapter-node: Unable to find certain packages in built app

See original GitHub issue

Describe the bug

Certain packages don’t seem to get exported into the build when using the node adapter. npm run preview for the built app works fine, but if the build folder is run as a stand-alone node server using a barebones package.json and with the command node index.js, the following error appears for some packages:

internal/process/esm_loader.js:74 internalBinding(‘errors’).triggerUncaughtException( ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package ‘pg-promise’ imported from /home/sridhar/work/occ/data-dashboard/workspace/builds/node_v4/index.js at packageResolve (internal/modules/esm/resolve.js:655:9) at moduleResolve (internal/modules/esm/resolve.js:696:18) at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11) at Loader.resolve (internal/modules/esm/loader.js:86:40) at Loader.getModuleJob (internal/modules/esm/loader.js:230:28) at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40) at link (internal/modules/esm/module_job.js:55:36) { code: ‘ERR_MODULE_NOT_FOUND’ }

This doesn’t happen for all packages though. In my demo app, there are three packages in production dependencies. While svelte-frappe-charts, dotenv work fine, pg and pg-promise don’t.

Due to this, deployment to an environment like AWS fails, with the same Error [ERR_MODULE_NOT_FOUND] error. Is this an issue with adapter-node related to the packages?

Reproduction

I’ve created a demo repo here - https://github.com/sridharraman/sveltekit-api-chart

If you want to test the api endpoint, you can run the following SQL statements in your database:

create table orders( id integer primary key, name text );

insert into orders(id, name) values (1, ‘Lorem’); insert into orders(id, name) values (2, ‘Ipsum’); insert into orders(id, name) values (3, ‘Scriptum’);

In the dev environment, these are the links that work fine: localhost:3000/api/orders localhost:3000/chart

They show that the database and chart packages work fine.

Logs

internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'pg-promise' imported from /home/user/work/build/index.js
    at packageResolve (internal/modules/esm/resolve.js:655:9)
    at moduleResolve (internal/modules/esm/resolve.js:696:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)
    at Loader.resolve (internal/modules/esm/loader.js:86:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:230:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40)
    at link (internal/modules/esm/module_job.js:55:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

System Info

System:
    OS: Linux 5.11 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i5-3337U CPU @ 1.80GHz
    Memory: 250.76 MB / 7.65 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.15.3 - ~/.nvm/versions/node/v14.15.3/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 7.16.0 - ~/.nvm/versions/node/v14.15.3/bin/npm
  Browsers:
    Chrome: 92.0.4515.107
    Firefox: 90.0.2
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.39 => 1.0.0-next.39 
    @sveltejs/adapter-vercel: next => 1.0.0-next.27 
    @sveltejs/kit: next => 1.0.0-next.142 
    svelte: ^3.34.0 => 3.42.1

Severity

blocking all usage of SvelteKit

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ignatiusmbcommented, Aug 9, 2021

You’re free to do it however you like, I suggest you seek help on either the Discord or Stack Overflow.


From the relevant PR #1648

This means that, in production, you should be able to copy over your package.json and build/, run npm install --production, and run node build - which is what you’d expect to be able to do.

It seems this hasn’t been properly documented in the package readme, which is pretty important as we had similar issues with deploying Sapper app back then. Marking as a documentation issue instead.

0reactions
sridharramancommented, Aug 9, 2021

svelte-frappe-charts exposes a “svelte” key in its package file, which SvelteKit uses to determine if it’s a Svelte package and bundles them regardless where we put it.

Ah understood. But for packages that expose a "svelte" key, they don’t get bundled. That makes sense.

You should make sure the dependencies in the original package.json exists in the server.

So, if I am using AWS EB to deploy the build app, how do I do it? Do I have to install the dependencies in the package.json within the build folder? And then push the folder to AWS? Or is there a better approach?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find package '@sveltejs/kit' on production build · Issue ...
When I create a new SvelteKit project with the node adapter and try to use the files in the build directory, I get...
Read more >
@sveltejs/adapter-node - npm
Adapter for SvelteKit apps that generates a standalone Node server. Usage. Install with npm i -D @sveltejs/adapter-node , then add the adapter ......
Read more >
cannot find package sveltejs/adapter-auto svelte.config.js
I am using VS Code for the project. The issue is related to opening the project in VS Code, opening a terminal, and...
Read more >
sveltekit require is not defined - You.com | The AI Search ...
Using SvelteKit with smartsheet API npm package to fetch data from smartsheet ... My sveltekit app fails to start, and shows 500 Internal...
Read more >
I cannot build my sveltekit project with any adapter! failed to ...
Try installing the latest version of the adapter. ex. npm install @sveltejs/adapter-netlify@next. I was having trouble building with the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found