简体   繁体   中英

throwing error while creating production build when using npm install --production

I have installed brotli-webpack-plugin as a devDependency . While trying to create production build using npm run build (internally it calls next build ), it throws following error

Error: Cannot find module 'brotli-webpack-plugin'.

I am using this plugin inside next.config.js .

During my production build, I want to do npm install --production to reduce the container size. What should I do ?

If i use npm istall only, then the build is being created without any error. Should I move that package from devDependency to dependency ?

I'm guessing you want to do this:

  1. Install dependencies.
  2. Build app
  3. Create container ( I assume you are using Docker for containerisation )

And you want to add only the production dependencies. The module that throws you the error is needed in build phase and if you install only production dependencies the build won't succeed. Assuming you are using a terminal or anything with bash do something like this:

  1. rm -rf node_modules ( this cleans your dependencies )
  2. npm install ( install all dependencies )
  3. npm build ( or any of your build commands )
  4. rm -rf node_modules ( here you clean again the dependencies because you already have the build done )
  5. npm install --production ( there you have it - dependencies only for production )
  6. Whatever command which creates your docker container

Should work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM