aralroca / next-translate-plugin

Next-translate plugin for i18n in Next.js 🌍 - Load page translations and use them in an easy way!
MIT License
32 stars 20 forks source link

Are you sure next-translate-plugin should be a dev dependency? #65

Open brunoscopelliti opened 1 year ago

brunoscopelliti commented 1 year ago

What version of this package are you using?

next: 13.4.11
next-translate: 2.5.2
next-translate-plugin: 2.5.2

What operating system, Node.js, and npm version?

Docker image

node:18.15.0-alpine3.17

What happened?

After building next.js project I delete the dev dependencies, and start the project. When I start the project i get this error:

Error: Cannot find module 'next-translate-plugin'
Require stack:
- /app/next.config.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
at /app/node_modules/next/dist/server/require-hook.js:113:36
at Module._load (node:internal/modules/cjs/loader:920:27)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/app/next.config.js:1:23)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/next.config.js' ]
}
Node.js v18.15.0
Container called exit(1).

I fixed the problem, installing next-translate-plugin as a normal dependency, but this surprised me a bit cause in the readme it is stated that next-translate-plugin is a dev dependency.

What did you expect to happen?

I didn't expect to have to keep next-translate-plugin around after building the project.

aralroca commented 1 year ago

It is curious because it only runs during build, not in runtime. But well, put it in dependencies for now and I will investigate why it happens, because it shouldn't be necessary. Thanks @brunoscopelliti to report it

StLyn4 commented 1 year ago

If I understand correctly, when the production server starts, it loads next.config.js. the webpack function is not executed, but the module is required at the beginning of the file anyway. So, in theory, all next.js plugins should be declared in dependencies

aralroca commented 1 year ago

Thanks for the clarification @StLyn4

Tronder commented 2 months ago

We also ended in the devDependency trap, maybe someone could update this error message when running the app without next-translate-plugin installed: image