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

@sveltejs/kit is resolving modules from the wrong directory #413

Closed
GrygrFlzr opened this issue Mar 2, 2021 · 2 comments
Closed

@sveltejs/kit is resolving modules from the wrong directory #413

GrygrFlzr opened this issue Mar 2, 2021 · 2 comments

Comments

@GrygrFlzr
Copy link
Member

GrygrFlzr commented Mar 2, 2021

Describe the bug
kit is importing relative to its location in node_modules, not relative to the initialized project:

UnhandledPromiseRejectionWarning: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'C:\Users\GrygrFlzr\Documents\projects\sk-35\node_modules\@sveltejs\kit\node_modules\@sveltejs\vite-plugin-svelte\' imported from C:\Users\GrygrFlzr\Documents\projects\sk-35\node_modules\@sveltejs\kit\dist\index2.js

Note \node_modules\@sveltejs\kit\node_modules\@sveltejs\vite-plugin-svelte\ instead of \node_modules\@sveltejs\vite-plugin-svelte\.

To Reproduce

# initialize a new project
# install vite to work around #412
$ npm run dev

> sk-35@0.0.1 dev C:\Users\GrygrFlzr\Documents\projects\sk-35
> svelte-kit dev

(node:304) UnhandledPromiseRejectionWarning: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'C:\Users\GrygrFlzr\Documents\projects\sk-35\node_modules\@sveltejs\kit\node_modules\@sveltejs\vite-plugin-svelte\' imported from C:\Users\GrygrFlzr\Documents\projects\sk-35\node_modules\@sveltejs\kit\dist\index2.js
    at legacyMainResolve (internal/modules/esm/resolve.js:225:9)
    at packageResolve (internal/modules/esm/resolve.js:648:14)
    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)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:304) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:304) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected behavior
Load dependencies from the correct directory

Information about your SvelteKit Installation:

  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.35
    svelte: ^3.29.0 => 3.35.0

Severity
Completely unusable without monkey-patching @sveltejs/kit.

Additional context
In not-svelte-kit I fixed this issue by using import-meta-resolve, but I'm a bit more hesitant to add a new dependency to the official solution.

Workaround: Run npm run build inside node_modules\@sveltejs\kit\node_modules\@sveltejs\vite-plugin-svelte.

@Rich-Harris
Copy link
Member

I think this is correct — vite-plugin-svelte is a dependency of Kit, not the project that uses it. I think the problem is that the vite-plugin-svelte package doesn't include the index.js, inexplicably. Fixed that in 8a9fcd6#diff-9b4d1e1724c3935da1984287277aace763e8a724298cb3b0c9db6d444d0d763a but now I'm struggling to convince npm to install that version in my project, I think because pnpm pins dependency versions when it publishes packages. Will cut a new Kit version to work around it

@GrygrFlzr
Copy link
Member Author

Can confirm the version bump seems to have fixed this.

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