项目设置:
- Vuejs 3
- 网络包 4
- 通天塔
- TS
我们使用创建项目vue-cli
并将依赖项添加到库中。
然后我们导入了一个使用可选链接的项目( Vue Currency Input v2.0.0 )。serve
但是我们在执行脚本时遇到以下错误:
error in ./node_modules/vue-currency-input/dist/index.esm.js
Module parse failed: Unexpected token (265:36)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| getMinValue() {
| let min = this.toFloat(-Number.MAX_SAFE_INTEGER);
> if (this.options.valueRange?.min !== undefined) {
| min = Math.max(this.options.valueRange?.min, this.toFloat(-Number.MAX_SAFE_INTEGER));
| }
我读到 Webpack 4 默认不支持可选链接。因此,我们为可选链添加了 Babel 插件。这是我们的babel.config.js
文件:
module.exports = {
presets: ["@vue/cli-plugin-babel/preset"],
plugins: ["@babel/plugin-proposal-optional-chaining"],
};
(但是,如果我是正确的,这个插件现在默认启用在babel-preset
.所以这个修改可能没用^^)
我不明白的一件事是我们可以在.vue
文件中使用可选链接。
我用所有文件创建了一个沙盒:沙盒
我该如何解决这个错误?