vue-cli: @vue/cli 4.0.5 transpileDependencies invalid
Version
4.0.5
Reproduction link
https://github.com/lxfu/vue-g6
Environment info
Mac、IE11
Steps to reproduce
npm i npm run serve
What is expected?
app should work under IE11.
What is actually happening?
The arrow function inside the dependency is not compiled
IE11 does not support arrow functions
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (7 by maintainers)
Commits related to this issue
- fix: add `sourceType: 'unambiguous'` to babel preset fixes #4773 — committed to sodatea/vue-cli by sodatea 5 years ago
- fix: add `sourceType: 'unambiguous'` to babel preset (#4797) fixes #4773 — committed to vuejs/vue-cli by sodatea 5 years ago
@JessicaSachs If you mean this issue https://github.com/vue-styleguidist/vue-styleguidist/issues/436, I believe it’s not related to the
sourceTypeconfiguration.@LinusBorg
According to the babel documentation,
unambiguousseems to be a safer option than the defaultmodule, especially when dealing with third-party dependencies.The edge cases are ambiguous modules as listed in https://github.com/tc39/proposal-UnambiguousJavaScriptGrammar#problem
For such a simple and ambiguous file, if no polyfills/helpers are injected:
sourceType: 'module', a"use strict"pragma would be added to the top of that file and the whole module will run in strict mode.sourceType: 'unambiguous', it will be considered a CommonJS module and remain as-is.I think the latter one is more reasonable in the context of third-party dependencies.
The real problem:
If a module references something like
Symboland a polyfill module needs to be added:sourceType: 'module', animportstatement will be injected to the file, regardless of the presence ofmodule.exports;sourceType: 'unambiguous', anrequirestatement will be injected if noimport/exportis seen in the file.Because we disabled the module transformation in babel, all
import/requirestatements are passed down to webpack as-is. And the former case will encounter an error in webpack runtime because webpack has stricter rules on ES modules (theexportsobject would be read-only). And that’s exactly the case in this issue.This also means, if we don’t change the default
sourceTypeconfiguration, all third-party CommonJS dependencies with partially transpiled code will encounter similar problems.These use cases are also described in the README (the 3rd option). We currently recommend users to set
useBuiltIns: 'entry', which is quite unintuitive and also sub-optimal in code size. So I believesourceType: 'unambiguous'could be a much better solution.we could experiment with it in a beta release, maybe?
Plus we can document that babel’s
overridesoption can be used to fine-tune this for individual packages/files if necessary:I this setting safe for arbitrary dependencies? Afaik it’s only necessary when attempting to transpile a module that’s using the commonjs module format.