Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

fix(vite): external modules under/esm/ pattern#1949

Merged
pi0 merged 2 commits into
mainfrom
fix/dev-bundler-external
Nov 16, 2021
Merged

fix(vite): external modules under/esm/ pattern#1949
pi0 merged 2 commits into
mainfrom
fix/dev-bundler-external

Conversation

@antfu

@antfu antfu commented Nov 16, 2021

Copy link
Copy Markdown
Member

Co-authored-by: Ben bencodezen@users.noreply.github.com

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Found during pairing with @bencodezen 🙌

To reproduce the bug (Vite):

<script setup lang="ts">
import format from 'date-fns/format'

const date = format(new Date(), 'yyyy/MM/dd')
</script>

<template>
  <div>
    {{ date }}
  </div>
</template>

which will cause the error of export is not a valid syntax. Searching down, the root cause is that the internal module of date-fns been externalized but in a .js format of ESM in server.mjs

This PR adds the conversion to externalize modules under /esm/ which I believe is a common pattern (date-fns is using is at least).

https://unpkg.com/browse/date-fns@2.25.0/esm/_lib/protectedTokens/index.js

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Co-authored-by: Ben <bencodezen@users.noreply.github.com>
@netlify

netlify Bot commented Nov 16, 2021

Copy link
Copy Markdown

✔️ Deploy Preview for nuxt3-docs canceled.

🔨 Explore the source changes: c8a3030

🔍 Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/6193a98b19e19b00082b0538

Comment thread packages/vite/src/server.ts Outdated
@pi0

pi0 commented Nov 16, 2021

Copy link
Copy Markdown
Member

Also made unjs/mlly#23 to resolve for mlly/externality

Co-authored-by: pooya parsa <pyapar@gmail.com>
@pi0 pi0 merged commit 86a47a2 into main Nov 16, 2021
@pi0 pi0 deleted the fix/dev-bundler-external branch November 16, 2021 13:28
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants