简体   繁体   English

Laravel mix 4 Amcharts动态导入问题

[英]Laravel mix 4 Amcharts dynamic import issue

I am using Laravel Mix but behind the scenes it uses Webpack 4. I cannot get rid of this error no matter what I do. 我正在使用Laravel Mix,但在幕后使用Webpack 4.无论我做什么,我都无法摆脱这个错误。

ERROR in ./node_modules/@amcharts/amcharts4/.internal/core/export/Export.js 3215:14
Module parse failed: Unexpected token (3215:14)
You may need an appropriate loader to handle this file type.
|             return [4
|             /*yield*/
>             , import(
|             /* webpackChunkName: "canvg" */
|             "canvg")];
 @ ./node_modules/@amcharts/amcharts4/core.js 74:0-56 74:0-56
 @ ./node_modules/babel-loader/lib??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./resources/assets/js/modules/Reporting/components/index.vue?vue&type=script&lang=js&
 @ ./resources/assets/js/modules/Reporting/components/index.vue?vue&type=script&lang=js&
 @ ./resources/assets/js/modules/Reporting/components/index.vue
 @ ./resources/assets/js/routes.js
 @ ./resources/assets/js/app.js
 @ multi ./resources/assets/js/app.js ./resources/assets/less/app.less

It looks like Amchart is doing dynamic import so I installed @babel/plugin-syntax-dynamic-import but no help. 看起来Amchart正在进行动态导入,所以我安装了@ babel / plugin-syntax-dynamic-import但没有帮助。 This plugin was not installed previously and Amcharts worked just fine. 之前没有安装此插件,Amcharts工作得很好。 Here are all the babel packages loaded: 以下是所有加载的babel包:

"devDependencies": {
  "@babel/cli": "^7.2.3",
  "@babel/core": "^7.2.2",
  "@babel/plugin-proposal-object-rest-spread": "^7.2.0",
  "@babel/plugin-syntax-dynamic-import": "^7.2.0",
  "@babel/preset-env": "^7.2.3",

And here is my .babelrc 这是我的.babelrc

{
  "presets": [
    "@babel/preset-env"
  ],
  "plugins": [
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-syntax-dynamic-import"
  ]
}

What am I doing wrong here? 我在这做错了什么? Should I be compiling node_modules/@amcharts ? 我应该编译node_modules / @amcharts吗? That doesn't make any sense, shouldn't node modules be already compiled? 这没有任何意义,不应该编译节点模块吗?

npm -v 6.4.1 node -v 10.14.1

Check your webpack version if it is higher than 4.28.4 you are out of luck. 检查你的webpack版本是否高于4.28.4你运气不好。 Webpack maintainers are now aware of this problem and the next version NPM version should solve the problem. Webpack维护者现在意识到这个问题,下一版本的NPM版本应该可以解决这个问题。 Somehow packages are hoisting incorrectly in the NPM tree. 不知何故,包裹在NPM树中不正确地吊装。 In the meantime quick fix that worked for me: 与此同时,快速解决方案对我有用:

Remove node_modules and destroy lock file 删除node_modules并销毁锁定文件

rm -fr node_modeles
rm -f package-lock.json

Downgrade webpack to last known working version (lock it there so you can run npm update for other packages): 将webpack降级到上一个已知的工作版本(将其锁定在那里,以便为其他软件包运行npm update):

npm install webpack@4.28.4

Install acorn 6.0 if your NPM cannot find it (this is NPM hoisting issue) 如果您的NPM找不到它,请安装acorn 6.0(这是NPM吊装问题)

npm install acorn@^6.0.0

You should be good to go! 你应该好好去!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM