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

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'svelte' #6837

Closed
binajmen opened this issue Sep 15, 2022 · 8 comments
Closed

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'svelte' #6837

binajmen opened this issue Sep 15, 2022 · 8 comments
Milestone

Comments

@binajmen
Copy link

Describe the bug

I successfully deployed my SvelteKit on Fly.io (using the Node adapter).

Unfortunately, I got the following error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'svelte' imported from /myapp/node_modules/typesafe-i18n/svelte/index.mjs
   at new NodeError (node:internal/errors:387:5)  
   at packageResolve (node:internal/modules/esm/resolve:951:9)  
   at moduleResolve (node:internal/modules/esm/resolve:1000:20) 
   at defaultResolve (node:internal/modules/esm/resolve:1214:11)  
   at nextResolve (node:internal/modules/esm/loader:165:28) 
   at ESMLoader.resolve (node:internal/modules/esm/loader:844:30) 
   at ESMLoader.getModuleJob (node:internal/modules/esm/loader:431:18)  
   at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40) 
   at link (node:internal/modules/esm/module_job:75:36)

Reproduction

Unfortunately, I'm unable to reproduce in local 😕

Is there a link with #1257 or #3137 or is it an issue with typesafe-i18n itself?

Logs

No response

System Info

System:
    OS: macOS 12.5.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 489.64 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.8.0 - ~/.nvm/versions/node/v18.8.0/bin/node
    npm: 8.18.0 - ~/.nvm/versions/node/v18.8.0/bin/npm
  Browsers:
    Brave Browser: 105.1.43.89
    Chrome: 105.0.5195.102
    Safari: 15.6.1
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.71 
    @sveltejs/adapter-node: next => 1.0.0-next.88 
    @sveltejs/kit: ^1.0.0-next.483 => 1.0.0-next.483 
    svelte: ^3.50.1 => 3.50.1 
    vite: ^3.1.0 => 3.1.0

Severity

blocking all usage of SvelteKit

Additional Information

No response

@binajmen
Copy link
Author

Is this #1450 (comment) confirmed?

For @sveltejs/adapter-node
"@sveltejs/kit": "next"
"svelte": "^3.34.0"
are needed as (production) dependencies.

@binajmen
Copy link
Author

binajmen commented Sep 15, 2022

So I switched the svelte package from dev (-D) to prod (-P) dependency, redeployed, and it is now working.

Although, from the previous issues, I understand this is not good/expected:

In the meantime as a workaround, you can move @sveltejs/kit and any other dependencies your app needs at runtime from devDependencies to dependencies but this obviously isn't a great solution.

@binajmen binajmen changed the title Cannot find package 'svelte' Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'svelte' Sep 16, 2022
@Rich-Harris
Copy link
Member

Does the same thing happen if you run node build after building the app locally? If so, you can provide a reproduction. My guess would be that typesafe-i18n is a prod dependency in your app, and since it has svelte as an undeclared peer dependency, svelte must also be a prod dependency.

If that's the case, I suggest trying to move typesafe-i18n to devDependencies.

@Rich-Harris
Copy link
Member

cc'ing @ivanhofer for visibility as well 👋

@Rich-Harris Rich-Harris added this to the whenever milestone Sep 19, 2022
@ivanhofer
Copy link
Contributor

@binajmen you can add typesafe-i18n to the devDependencies but then you need to instruct vite to also add typesafe-i18n to your bundle. Adding those lines should fix the issue for you:

vite.config.js

export default defineConfig({
	plugins: [sveltekit()],
+	ssr: {
+		noExternal: ['typesafe-i18n'],
+	},
})

@binajmen
Copy link
Author

binajmen commented Sep 20, 2022

@binajmen you can add typesafe-i18n to the devDependencies but then you need to instruct vite to also add typesafe-i18n to your bundle. Adding those lines should fix the issue for you:

@ivanhofer This solve the issue indeed 👍 I don't fully understand the impact though. Is there one? Is this more a workaround that a final solution? Should we continue to track the issue or can it be closed?

Does the same thing happen if you run node build after building the app locally? If so, you can provide a reproduction.

@Rich-Harris Unfortunately I'm unable to reproduce locally. I'm not sure why.. If you think it should be further investigated, I don't mind take the time (later this week) to create a small repro of my current project. This is non blocking so the milestone whenever tag is appropriated 😉

@ivanhofer
Copy link
Contributor

I don't fully understand the impact though. Is there one? Is this more a workaround that a final solution? Should we continue to track the issue or can it be closed?

I would see this as a final solution. It does not really matter if you bundle typesafe-i18n into your production application or to have it installed as a dependency.

Unfortunately I'm unable to reproduce locally. I'm not sure why..

The issue is that Fly.io (and most other node hosting services) get rid of all devDependencies once the build process was completed. In order to reproduce this locally, you would need to:

  1. run the build process
  2. manually uninstall all devDependencies
  3. start the application

@binajmen
Copy link
Author

I would see this as a final solution.

Then I can safely close this issue as it solves my problem 👍

The issue is that Fly.io (and most other node hosting services) get rid of all devDependencies

In my case, based on some inspiration I found on the web (being a Docker beginner), I run:

RUN npm prune --production

Which gets rid of devDependencies, indeed. I'll stick to your solution ;)

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

3 participants