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

bug(netlify): Package subpath './hooks' is not defined by "exports" #3189

Closed
Mrbeyond opened this issue Jan 3, 2022 · 18 comments · Fixed by #3327
Closed

bug(netlify): Package subpath './hooks' is not defined by "exports" #3189

Mrbeyond opened this issue Jan 3, 2022 · 18 comments · Fixed by #3327
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-netlify
Milestone

Comments

@Mrbeyond
Copy link

Mrbeyond commented Jan 3, 2022

Describe the bug

Sveltekit app having version "svelte": "^3.44.0" works perfectly locally but showing "errorMessage":"Package subpath './ssr' is not defined by "exports" in /var/task/node_modules/@sveltejs/kit/package.json" when deployed to production on netlify. I have tried both auto-adapter and explicit netlify adapter but the error persists.

Reproduction

Repo link:
https://github.com/Mrbeyond/pubside

Logs

{"errorType":"Error","errorMessage":"Package subpath './ssr' is not defined by \"exports\" in /var/task/node_modules/@sveltejs/kit/package.json","trace":["Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './ssr' is not defined by \"exports\" in /var/task/node_modules/@sveltejs/kit/package.json","    at new NodeError (internal/errors.js:322:7)","    at throwExportsNotFound (internal/modules/esm/resolve.js:322:9)","    at packageExportsResolve (internal/modules/esm/resolve.js:511:7)","    at resolveExports (internal/modules/cjs/loader.js:450:36)","    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)","    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)","    at Function.Module._load (internal/modules/cjs/loader.js:746:27)","    at Module.require (internal/modules/cjs/loader.js:974:19)","    at require (internal/modules/cjs/helpers.js:93:18)","    at Object.<anonymous> (/var/task/.netlify/server/app.js:45:29)"]}

System Info

"devDependencies": {
    "@sveltejs/adapter-auto": "next",
    "@sveltejs/adapter-netlify": "^1.0.0-next.37",
    "@sveltejs/kit": "next",
    "autoprefixer": "^10.4.1",
    "cssnano": "^5.0.14",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-svelte3": "^3.2.1",
    "node-sass": "^7.0.1",
    "postcss-load-config": "^3.1.0",
    "prettier": "^2.4.1",
    "prettier-plugin-svelte": "^2.4.0",
    "svelte": "^3.44.0",
    "svelte-preprocess": "^4.10.1",
    "tailwindcss": "^3.0.8"
  },

Severity

annoyance

Additional Information

No response

@bluwy
Copy link
Member

bluwy commented Jan 3, 2022

./ssr is definitely defined in package.json. Can you confirm the @sveltejs/kit version from the lockfile? The next version is vague. I also can't access the repo to verify it.

@Mrbeyond
Copy link
Author

Mrbeyond commented Jan 3, 2022

./ssr is definitely defined in package.json. Can you confirm the @sveltejs/kit version from the lockfile? The next version is vague. I also can't access the repo to verify it.

From lock file:
"node_modules/@sveltejs/kit": {
"version": "1.0.0-next.208",
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.208.tgz",
....
}

Oops, the repo is private, lemme provide another accessible repo, I will update it ASAP.

Thanks.

@Mrbeyond
Copy link
Author

Mrbeyond commented Jan 3, 2022

./ssr is definitely defined in package.json. Can you confirm the @sveltejs/kit version from the lockfile? The next version is vague. I also can't access the repo to verify it.

Repo:
https://github.com/Mrbeyond/pubside

@SSouper
Copy link

SSouper commented Jan 7, 2022

exactly the same issue here

in my experience the netlify adapter has always been subpar and broken/not prod ready compared to vercel which is sad :(
every time i try to deploy a site that relies on ssr to netlify it fails in some way or another and i keep going back to vercel

@Mrbeyond
Copy link
Author

Mrbeyond commented Jan 8, 2022

@SSouper

But it has always been working well on my projects until the recent svelte version.

@bluwy

This comment has been minimized.

@TheOnlyWayUp
Copy link

I completely disagree @bluwy. Even with your 'fix', there is no change. This is an issue with the netlify adapter for Svelte, who else would be responsible for such an issue?

@TheOnlyWayUp
Copy link

@SSouper

But it has always been working well on my projects until the recent svelte version.

I agree with @SSouper, it used to work, but compared to Vercel, it's pretty underwhelming, partiality at its finest :(

@bluwy
Copy link
Member

bluwy commented Jan 8, 2022

I completely disagree @bluwy. Even with your 'fix', there is no change. This is an issue with the netlify adapter for Svelte, who else would be responsible for such an issue?

Can you show what is the issue with the Netlify adapter? The export error doesn't make sense as we had always exported the ./ssr path. It's hard to debug this issue as the build works locally, and only fails in Netlify, which could likely mean the issue is within Netlify.

@stordahl
Copy link
Contributor

stordahl commented Jan 8, 2022

I'm getting this too right now - here's a live url where you can see the error.

Repo for this is here

Also to be clear, the build does complete on netlify which is odd - I normally only have issues with Netlify building. This makes me think it's something with the adapter

@bluwy
Copy link
Member

bluwy commented Jan 8, 2022

Ah I think I found the culprit. In .netlify/server/app.js, there is an import to @sveltejs/kit/ssr, but it doesn't work because we only export ESM code for it, while the generated output was CJS. This seems to be introduced in #2931. Perhaps we should bundle @sveltejs/kit/ssr? The error message was rather misleading.

@bluwy bluwy added bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-netlify and removed awaiting submitter labels Jan 8, 2022
@bluwy bluwy added this to the 1.0 milestone Jan 8, 2022
@benmccann
Copy link
Member

@sveltejs/kit/ssr was introduced 10 months ago in #454. But I guess that it ended up getting bundled via esbuild, so there was no issue. And then #2931 removed the second bundling step.

I agree that bundling @svelte/kit/ssr so that it exports CJS as well seems like perhaps the best solution

@benmccann benmccann linked a pull request Jan 14, 2022 that will close this issue
5 tasks
@tomatrow
Copy link

A very similar error still seems present in kit at version 232.

Bundling using esbuild is a workaround.

See this comment for configuring your netlify.toml.

The error:

{
  "errorType": "Error",
  "errorMessage": "Package subpath './hooks' is not defined by \"exports\" in /var/task/node_modules/@sveltejs/kit/package.json",
  "trace": [
    "Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './hooks' is not defined by \"exports\" in /var/task/node_modules/@sveltejs/kit/package.json",
    "    at new NodeError (internal/errors.js:322:7)",
    "    at throwExportsNotFound (internal/modules/esm/resolve.js:322:9)",
    "    at packageExportsResolve (internal/modules/esm/resolve.js:511:7)",
    "    at resolveExports (internal/modules/cjs/loader.js:450:36)",
    "    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)",
    "    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:746:27)",
    "    at Module.require (internal/modules/cjs/loader.js:974:19)",
    "    at require (internal/modules/cjs/helpers.js:93:18)",
    "    at Object.<anonymous> (/var/task/.netlify/server/app.js:61:31)"
  ]
}

@benmccann benmccann reopened this Jan 17, 2022
@benmccann benmccann changed the title App showing './ssr' not defined error on netlify bug(netlify): Package subpath './hooks' is not defined by "exports" Jan 18, 2022
@Rich-Harris
Copy link
Member

Can you try updating Kit and adapter-netlify to the most recent next versions?

npm i -D @sveltejs/kit@next @sveltejs/adapter-netlify@next @sveltejs/adapter-auto@next

@benmccann
Copy link
Member

Repo:
https://github.com/Mrbeyond/pubside

@Mrbeyond I get a 404 when trying to access your reproduction

@benmccann
Copy link
Member

Repo for this is here

@stordahl I'm not able to reproduce with this repository. I deployed the checked in code with no issues. I then removed the line node_bundler = "esbuild" from netlify.toml and redeployed and it still worked

@benmccann
Copy link
Member

I'm going to close this for now since there's no reproduction of it. I've also deployed my own projects to Netlify with the latest SvelteKit and didn't face any issues. We can reopen if someone provides a way to reproduce

@stordahl
Copy link
Contributor

Repo for this is here

@stordahl I'm not able to reproduce with this repository. I deployed the checked in code with no issues. I then removed the line node_bundler = "esbuild" from netlify.toml and redeployed and it still worked

My issues were fixed in #3327 - I was seeing this error with the subpath './srr' not './hooks'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-netlify
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants