【问题标题】:Error: Cannot find module '@babel/plugin-syntax-dynamic-import' in symfony project错误:在 symfony 项目中找不到模块“@babel/plugin-syntax-dynamic-import”
【发布时间】:2020-09-05 15:59:17
【问题描述】:

我按照 symfony 文档在我的项目中启用 webpack encore:https://symfony.com/doc/5.1/frontend/encore/installation.html

我发出的命令:

> brew install node
> npm install -g yarn
> cd ~/path/to/project
> yarn set version berry
> composer require symfony/webpack-encore-bundle
> yarn install

尽管yarn install 产生了一些关于未能构建某些包的警告,但它们都成功运行。

之后我执行yarn encore dev 时出现以下错误:

 ERROR  Failed to compile with 1 errors                                                                                                                                                                                                                                                                       3:09:15 PM

 error  in ./assets/js/app.js

Syntax Error: Error: Cannot find module '@babel/plugin-syntax-dynamic-import' from '~/path/to/project'
    at Array.map (<anonymous>)
    at cachedFunction.next (<anonymous>)
    at Generator.next (<anonymous>)
    at buildRootChain.next (<anonymous>)
    at loadPrivatePartialConfig.next (<anonymous>)
    at Generator.next (<anonymous>)
    at Generator.next (<anonymous>)
    at new Promise (<anonymous>)

谷歌搜索只让我发现了一些 github 问题,这些问题似乎与从 babel 6 到 7 的切换有关,但正如我所做的全新安装,似乎没有连接。

附加信息:

  • 操作系统:macOS 10.15.6
  • 节点版本:v14.9.0

【问题讨论】:

    标签: symfony yarnpkg webpack-encore


    【解决方案1】:

    问题在于我盲目地相信文档。 Symfony 的 webpack 包似乎需要 yarn 1.x 才能正常运行,但 symfonys 文档中链接的 yarn 安装页面显示了如何在项目中安装 yarn2。在我用yarn set version classic 更改了项目的纱线版本后,下面的yarn install 再次产生了一些警告,但现在一切似乎都正常了。

    这是使我朝着正确方向前进的 github 问题:https://github.com/vuejs/vue-cli/issues/5135

    【讨论】:

    • 我犯了同样的错误。一旦我按照您所说的切换到版本 1,它就起作用了。我现在在我的项目中有一个 node_modules 文件夹。当我运行yarn encore dev它工作正常时,我不再有ERROR Cannot find module @babel plugin-syntax-dynamic-import 错误。
    猜你喜欢
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 2019-11-27
    • 2020-04-15
    • 1970-01-01
    • 2022-08-15
    • 2021-10-28
    • 1970-01-01
    相关资源
    最近更新 更多