@sveltejs/adapter-node: Unable to find certain packages in built app
See original GitHub issueDescribe 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:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
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
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.
Ah understood. But for packages that expose a
"svelte"
key, they don’t get bundled. That makes sense.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?