Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@sveltejs/kit' on production build
See original GitHub issueDescribe the bug
When I create a new SvelteKit project with the node
adapter and try to use the files in the build
directory, I get the following error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@sveltejs/kit' imported from [...]
Logs
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@sveltejs/kit' imported from [REDACTED]/app.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'
}
To Reproduce
- create a new SvelteKit skeleton project
- add
adapter-node
to it - make sure all the deps have
"next"
as version yarn && yarn build
- isolate the
build
directory (I only want the production files in my production environment) by moving it somewhere else - add a
package.json
file to the directory with the contents:{ "type": "module" }
(for ESM) node .
<- This is what triggers the bug
Expected behavior
I expect the build
directory to contain everything that is needed to run the app in isolation. Adding the small package.json
file is another thing that I do not want to do myself.
When running node .
the server should just run.
Information about your SvelteKit Installation:
Diagnostics
System:
OS: macOS 11.2.3
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 5.37 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.16.0 - ~/.volta/tools/image/node/14.16.0/bin/node
Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
npm: 7.7.0 - ~/.volta/tools/image/npm/7.7.0/bin/npm
Browsers:
Chrome: 90.0.4430.85
Firefox: 87.0
Safari: 14.0.3
npmPackages:
@sveltejs/kit: ^1.0.0-next.74 => 1.0.0-next.91
svelte: ^3.29.0 => 3.37.0
vite: ^2.2.2 => 2.2.3
- Your adapter: Node
Severity It’s kind of annoying as I really want my production setup to be ready, but it doesn’t stop me from development.
Additional context All the above steps are done in a Dockerfile for production but I was able to reproduce it outside as well
Dockerfile
FROM node:14-alpine as build
ARG VITE_API_URL
RUN mkdir /svelte-build
WORKDIR /svelte-build
ENV VITE_API_URL=${VITE_API_URL}
COPY . .
RUN yarn && yarn build
FROM node:14-alpine as production
RUN addgroup -S app && adduser -S app -G app
RUN mkdir /app && chown app:app /app
USER app
WORKDIR /app
RUN echo '{ "type": "module" }' > /app/package.json
COPY --chown=app:app --from=build /svelte-build/build/ /app
EXPOSE 3000
CMD node index.js
Issue Analytics
- State:
- Created 2 years ago
- Reactions:13
- Comments:8 (3 by maintainers)
Top Results From Across the Web
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 >Adapters • Docs • SvelteKit
Adapters are small plugins that take the built app as input and generate output for deployment. By default, projects are configured to use...
Read more >@sveltejs/kit - npm
This is the SvelteKit framework and CLI. The quickest way to get started is via the create-svelte package: npm create svelte@latest my-app cd...
Read more >I cannot build my sveltekit project with any adapter! failed to ...
rollupOptions.external` Error: [vite]: Rollup failed to resolve import "@sveltejs/kit/ssr" from ".svelte/build/app.js".
Read more >SvelteKit $app cannot be found in svelte.config.js
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '$app' imported from ... { dev } from '$app/env'; /** @type {import('@sveltejs/kit').
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I noticed that I didn’t have “@sveltejs/adapter-node” in my dependencies. Now it’s building fine. I wonder if others are doing this by mistake as well.
@katkrasinsk what if you add
svelte
todependencies
too?