sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.71k stars 1.94k forks source link

Error building project - "Cannot find package 'cookie'" #4642

Closed callumgare closed 2 years ago

callumgare commented 2 years ago

Describe the bug

Following the instructions on https://github.com/sveltejs/kit/blob/master/CONTRIBUTING.md exactly I get the following error:

kit.svelte.dev:build: > Cannot find package 'cookie' imported from /private/tmp/kit/sites/kit.svelte.dev/.svelte-kit/output/server/index.js
kit.svelte.dev:build: Did you mean to import cookie@0.5.0/node_modules/cookie/index.js?
kit.svelte.dev:build: Did you mean to import cookie@0.5.0/node_modules/cookie/index.js?
kit.svelte.dev:build:     at new NodeError (node:internal/errors:372:5)
kit.svelte.dev:build:     at packageResolve (node:internal/modules/esm/resolve:908:9)
kit.svelte.dev:build:     at moduleResolve (node:internal/modules/esm/resolve:957:20)
kit.svelte.dev:build:     at defaultResolve (node:internal/modules/esm/resolve:1173:11)
kit.svelte.dev:build:     at ESMLoader.resolve (node:internal/modules/esm/loader:604:30)
kit.svelte.dev:build:     at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
kit.svelte.dev:build:     at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
kit.svelte.dev:build:     at link (node:internal/modules/esm/module_job:78:36)
kit.svelte.dev:build:  ELIFECYCLE  Command failed with exit code 1.
kit.svelte.dev:build: Error: command finished with error: command (sites/kit.svelte.dev) pnpm run build exited (1)
command (sites/kit.svelte.dev) pnpm run build exited (1)

Reproduction

I have literally just done the steps in https://github.com/sveltejs/kit/blob/master/CONTRIBUTING.md (deleting everything and trying again several times):

npm i -g pnpm
git clone git@github.com:sveltejs/kit.git
cd kit
pnpm install
pnpm build

Logs

No response

System Info

System:
    OS: macOS 12.3
    CPU: (10) arm64 Apple M1 Max
    Memory: 109.58 MB / 32.00 GB
    Shell: 3.4.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 17.9.0 - /opt/homebrew/bin/node
    npm: 8.5.5 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 100.0.4896.127
    Firefox: 99.0.1
    Safari: 15.4
  npmPackages:
    @sveltejs/eslint-config: github:sveltejs/eslint-config#v5.8.0 => 5.8.0

Severity

serious, but I can work around it

Additional Information

No response

Rich-Harris commented 2 years ago

Ah yeah, I know what this is about. Since #4588, SvelteKit depends on two new dependencies, cookie and set-cookie-parser. When running kit.svelte.dev locally, it copies over the src files in the kit package rather than the built asset files since that makes development easier, but for reasons I don't yet totally understand, that means Vite can't find those dependencies when you do svelte-kit build.

The easy fix is to add cookie and set-cookie-parser as devDependencies of kit.svelte.dev (we already do this for another dependency, devalue). But it doesn't feel like a very correct or scalable solution. Need to figure out why those dependencies aren't getting bundled. It applies to other parts of the repo as well (the adapter-static package has a devDependency on devalue for the same reason, as does kit-sandbox.

A temporary workaround is to do CI=true pnpm build instead of pnpm build, since in CI kit.svelte.dev uses the built files rather than the src files.

callumgare commented 2 years ago

Cool beans, to be honest I only really cared about building it to verify this PR https://github.com/sveltejs/kit/pull/4643. I'll leave this issue for you to do with what you will and close when you're happy with it :)

zachsa999 commented 2 years ago

Just tuning in here. I just ran into this issue, `import cookie from 'cookie'

zachsa999 commented 2 years ago

Whoops sent that one early.

DoisKoh commented 1 month ago

Is no one else still hitting this issue?