nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript ๐Ÿš€
https://nestjs.com
MIT License
66.91k stars 7.55k forks source link

Webpack: Invalid configuration object #11953

Closed cloakedch closed 1 year ago

cloakedch commented 1 year ago

Is there an existing issue for this?

Current behavior

I am running into the following error:

 Error  Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration has an unknown property 'exclude'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, experiments?, extends?, 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: {
           exclude: โ€ฆ
         }
       })
     ]

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-xquxyt

Steps to reproduce

1) Download latest NodeJS (v18.16.1) 2) Install latest NestJS via npm install -g @nestjs/cli or alternatively update via npm update -g 3) Run nest new test and choose npm as the package manager 4) Inside test run nest generate app test2 5) Try to run npm run build. Above error message is produced

Expected behavior

A valid build without webpack errors.

Package

Other package

No response

NestJS version

10.1.0

Packages versions

Node.js version

18.16.1

In which operating systems have you tested?

Other

No response

MarcosRava commented 1 year ago

same problem here

Debananda commented 1 year ago

same problem

micalevisk commented 1 year ago

@MarcosRava @Debananda

please don't send "+1" comments. Use reaction emojis instead ;) otherwise we'll have to lock this Issue due to unuseful notifications. Thanks.

Tony133 commented 1 year ago

If I understood the problem correctly by looking at the minimal reproduction of @cloakedch I downloaded , it could be fixed in the nest-cli.json file by changing "webpack": true to "builder": "webpack"

Before

...
   "compilerOptions": {
     "deleteOutDir": true,
     "webpack": true,
     "tsConfigPath": "apps/nest-typescript-starter/tsconfig.app.json"
   },
...

After

...
"compilerOptions": {
     "deleteOutDir": true,
     "builder": "webpack",
     "tsConfigPath": "apps/nest-typescript-starter/tsconfig.app.json"
   },
...

This change was made in v10 of nestjs-cli package(see here: https://github.com/nestjs/nest-cli/commit/f958183dcc9d721cb365294e8465d3fc28140240#diff-50d4a261e8cf91b9d15210fb0ceb896e2bdeb6c63101b3efd357e88f115f341bR15-R22), in fact in your ide or editor you should be able to read this message ( see screenshot )screen-cli

So maybe it is a configuration problem, which is causing the error.

I hope I have been helpful

cloakedch commented 1 year ago

@Tony133 thank you for your help. This helps to temporarily fix the problem. Since the code is generated using the nest cli command, I suspect the blueprints need to be updated?

Tony133 commented 1 year ago

@Tony133 thank you for your help. This helps to temporarily fix the problem.

You're welcome, it's nothing, ๐Ÿ˜‰๐Ÿ‘

Since the code is generated using the nest cli command, I suspect the blueprints need to be updated?

Maybe it's best to wait for Kamil on this point, to be sure.

However, I think we should specify this on the migrations page of the documentation, if my understanding is correct. ๐Ÿ˜„

Azim-Azizov commented 1 year ago

Hi.

I've found that this problem occurs only when I create sub-app (for ms). Nest-cli updates the tsconfig.build.json.

I did remove the line where exclude parts come in, and everything started working normally.

I don't know if this way of fixing is correct or not.

FYI: project that I was working on has been created an hour ago using nestjs cli.

MarcosRava commented 1 year ago

Using "builder": "webpack" it's ignoring webpack.config.js for me

kamilmysliwiec commented 1 year ago

Fixed in 10.1.1