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

SSR resolve always happens as require even when it's an import #10352

Closed
7 tasks done
benmccann opened this issue Oct 5, 2022 · 2 comments · Fixed by #10371 or #11101
Closed
7 tasks done

SSR resolve always happens as require even when it's an import #10352

benmccann opened this issue Oct 5, 2022 · 2 comments · Fixed by #10371 or #11101
Labels
feat: ssr p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@benmccann
Copy link
Collaborator

benmccann commented Oct 5, 2022

Describe the bug

Svelte has a package.json in each directory to support older versions of Node. On Node 12+ the exports map will be used. Even on newer versions of Node, Vite appears to be looking at the nested package.json rather than the exports map, which is incorrect. This only happens with the external config.

Originally reported in sveltejs/vite-plugin-svelte#360

Reproduction

git clone git@github.com:benmccann/context-issue.git
cd context-issue/svelte-kit-app
npm install
npm run dev

System Info

System:
    OS: macOS 12.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 293.67 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.9.0 - ~/.nvm/versions/node/v17.9.0/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v17.9.0/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v17.9.0/bin/npm
  Browsers:
    Chrome: 102.0.5005.61
    Firefox: 100.0.2
    Safari: 15.4
    Safari Technology Preview: 15.4
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.50 
    @sveltejs/kit: next => 1.0.0-next.347 
    svelte: ^3.44.0 => 3.48.0

Used Package Manager

npm

Logs

No response

Validations

@benmccann benmccann added bug p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) labels Oct 5, 2022
@benmccann
Copy link
Collaborator Author

There's at least a couple bugs here.

The first is that it appears to try multiple packages before looking for an exports field:

const possiblePkgId = nestedPath.slice(0, slashIndex)

The second is that it hardcodes isRequire: true which is wrong nearly 100% of the time for SvelteKit projects:

It's possible there's still be more wrong after that, but fixing those would be a good start.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2022
@benmccann benmccann changed the title Nested package.json used for resolving rather than exports field SSR resolve always happens as require even when it's an import Nov 17, 2022
@benmccann
Copy link
Collaborator Author

benmccann commented Nov 17, 2022

Reopening since the isRequire portion of the fix was reverted: #10569

Also, @aleclarson pointed out a tweak that may be needed for the remaining piece of the fix: #10371 (comment)

@benmccann benmccann reopened this Nov 17, 2022
@benmccann benmccann linked a pull request Nov 28, 2022 that will close this issue
9 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: ssr p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
1 participant