2

I followed the symfony documentation to enable webpack encore in my project: https://symfony.com/doc/5.1/frontend/encore/installation.html

Commands i issued:

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

They all ran through successfully, though yarn install yielded some warnings about failing to build some packages.

When i executed yarn encore dev afterwards i got following error:

 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>)

Googling around has only led me to some github issues where the problem seemed to be related to the switch from babel 6 to 7, but as i did a fresh install that does not seem to be connected.

Additional Info:

  • OS: macOS 10.15.6
  • Node Version: v14.9.0
larscm
  • 156
  • 3
  • 11

1 Answers1

2

The problem lay in me trusting the documentation blindly. Symfony's webpack bundle seems to need yarn 1.x to function properly, but the yarn install page linked in the symfonys docs shows how to install yarn2 inside the project. After I changed the project's yarn version with yarn set version classic, the following yarn install yielded some warnings again, but everything seems to work fine now.

This is the github issue that headed me in the right direction: https://github.com/vuejs/vue-cli/issues/5135

larscm
  • 156
  • 3
  • 11
  • 1
    I made exactly the same mistake. Once I switched to version 1 as you said, it worked. I now have a node_modules folder on my project. When I run `yarn encore dev`it works fine, I no longer have `ERROR Cannot find module @babel plugin-syntax-dynamic-import` error. – Droom Oct 11 '20 at 05:54