Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack 5 support #103

Open
acallaghan opened this issue Aug 28, 2021 · 4 comments
Open

Webpack 5 support #103

acallaghan opened this issue Aug 28, 2021 · 4 comments

Comments

@acallaghan
Copy link

Hi there, So i'm testing out Webpacker 6 which uses webpack 5 - I'm having trouble initializing the loader.

module.exports = {
  test: /\.erb$/,
  enforce: "pre",
  exclude: /node_modules/,

  use: [{
    loader: "rails-erb-loader",
    options: {
      runner: (/^win/.test(process.platform) ? "ruby " : "") + "bin/rails runner",
      env: {
        ...process.env,
        DISABLE_SPRING: 1,
      },
    },
  }],
}

Which gives me this error

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration has an unknown property 'use'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, experiments?, externals?, externalsPresets?, externalsType?, ignoreWarnings?, infrastructureLogging?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, snapshot?, stats?, target?, watch?, watchOptions? }
   -> Options object as provided by the user.
   For typos: please correct them.
   For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.
     Loaders should be updated to allow passing options via loader options in module.rules.
     Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
     plugins: [
       new webpack.LoaderOptionsPlugin({
         // test: /\.xxx$/, // may apply this only for some modules
         options: {
           use: …
         }
       })
     ]

Any ideas how to adapt the loader? Do you need to do work to support the new webpack 5 plugin API?

@rhys-vdw
Copy link
Collaborator

Any ideas how to adapt the loader?

First step is to add webpack 5 to the test suite here:

- TRAVIS_WEBPACK_VERSION="2"
- TRAVIS_WEBPACK_VERSION="3"
- TRAVIS_WEBPACK_VERSION="4"

"test-webpack-2": "npm install webpack@2 --no-save && jest",
"test-webpack-3": "npm install webpack@3 --no-save && jest",
"test-webpack-4": "npm install webpack@4 --no-save && jest"

However, it sounds as though you're simply providing the options to rails-erb-loader is an old way that is not longer valid:

configuration has an unknown property 'use'.

Additionally it sounds like the API for reading options may have changed:

For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration. Loaders should be updated to allow passing options via loader options in module.rules.

Note that in making required changes (if any) we will also need to continue to support older versions of webpack.

Additionally for this change to be complete we will need to update the README to show the current recommended way to configure webpack 5.

Do you need to do work to support the new webpack 5 plugin API?

I myself will not be making this change, but will happily accept a PR that does so, provided the above is included, or explanation is given as to why it was not required.

@PikachuEXE
Copy link
Collaborator

Webpacker 6 has already included a default rule for .erb files with rails-erb-loader as loader
(When the module rails-erb-loader can be resolved)

@acallaghan
Copy link
Author

@PikachuEXE Ah this is correct, and yes it 'just works' in webpacker 6 without any user config at all - thank you very much.

@rhys-vdw
Copy link
Collaborator

Reopening until we can confirm compatibility with webpack 5.

@rhys-vdw rhys-vdw reopened this Aug 31, 2021
@rhys-vdw rhys-vdw changed the title Webpacker 6 support Webpack 5 support Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants