34

While migrating from Webpack 4 to Webpack 5 I got an error when using devtool with empty value (only in production mode).

module.exports = {
    devtool: isProd ? '' : 'source-map',
    // entry: ...
    // output: ...
    // module: ...
}

The message in the console:

ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.devtool should match pattern "^(inline-|hidden-|eval-)?(nosources-)?(cheap-(module-)?)?source-map$".
   BREAKING CHANGE since webpack 5: The devtool option is more strict.
   Please strictly follow the order of the keywords in the pattern.

Any ideas how to avoid source maps in production mode? What to type in there?

3 Answers 3

60

Answer to own question! Spoiler: false.

module.exports = {
    devtool: isProd ? false : 'source-map',
}

In Webpack 4 it was possible to value this with an empty string. webpack 5 is more strict. Webpacks devtool configuration.

Sign up to request clarification or add additional context in comments.

2 Comments

What is isProd referencing to?
It's just a boolean whether the app is in production mode.
3

somehow my "source-map" had a # in it like "#source-map" that was causing this error. Solved the error by removing # from the string.

Before:

devtool: (config.enabled.sourceMaps ? '#source-map' : false)

After:

devtool: (config.enabled.sourceMaps ? 'source-map' : false)

Comments

0

Before: devtool: "#source-map" After: devtool: "source-map"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.