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

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

Merged
merged 2 commits into from Nov 16, 2021
Merged

Conversation

antfu
Copy link
Member

@antfu antfu commented Nov 16, 2021

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
Copy link

netlify bot commented Nov 16, 2021

βœ”οΈ Deploy Preview for nuxt3-docs canceled.

πŸ”¨ Explore the source changes: c8a3030

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/6193a98b19e19b00082b0538

packages/vite/src/server.ts Outdated Show resolved Hide resolved
@pi0
Copy link
Member

pi0 commented Nov 16, 2021

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.

None yet

3 participants