symfony / stimulus-bridge

Stimulus integration bridge for Symfony projects
https://symfony.com/ux
75 stars 15 forks source link

Could not retrieve module factory for controllers.json #32

Closed kayue closed 3 years ago

kayue commented 3 years ago

After upgrade Encore and the bridge to the latest version, I run into the following compile error:

(node:64945) [DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK] DeprecationWarning: Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader
(Use `node --trace-deprecation ...` to show where the warning was created)
 ERROR  Failed to compile with 1 errors                                                                                            4:50:59 PM

 error  in ./assets/controllers.json

Syntax Error: Error: Could not retrieve module factory for type LoaderDependency 

There error was triggered in here:

https://github.com/symfony/stimulus-bridge/blob/7b3d6ea1d9ed84e4cca81dd00f0511a9c92f6dba/dist/webpack/loader.js#L36-L42

The minimal webpack.config.js I can trigger the error is this

const Encore = require('@symfony/webpack-encore');

// Avoid creating .babelrc file to allow Encore manage Babel configuration
const babelConfig = (config) => {
    config.plugins.push('@babel/plugin-proposal-class-properties');
};

// Shop config
Encore
    .setOutputPath('public/build/shop/')
    .setPublicPath('/build/shop')
    .addEntry('shop-entry', './assets/shop/entry.js')
    .enableStimulusBridge('./assets/controllers.json')
    .enableTypeScriptLoader()
    .configureBabel(babelConfig, {
        corejs: 3,
        useBuiltIns: 'usage',
    })
    .disableSingleRuntimeChunk();

module.exports = [Encore.getWebpackConfig()];
kayue commented 3 years ago

I might have two webpack version installed in my project because Storybook doesn't fully support Webpack 5 yet, not sure is it going to be a problem.

kayue commented 3 years ago

Confirmed that it is related to Storybook 6.2 (beta).

Part of Storybook 6.2 (the ui manager) is still using webpack 4 and cause this error.

kayue commented 3 years ago

For people who uses Storybook 6.2, here is a solution: https://github.com/storybookjs/storybook/issues/14044