LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Linux, node_modules, webpack issue (https://www.linuxquestions.org/questions/linux-software-2/linux-node_modules-webpack-issue-4175735908/)

hljhende 04-11-2024 08:54 AM

Linux, node_modules, webpack issue
 
EDIT: I fixed it. The issue was NODE_ENV.
NODE_ENV was being changed from "development" to "production" by certain commands.
When NODE_ENV is set to production, devDependencies are not installed. So you should explicitly set it to 'development' by default.
It does seem to be linux related, because this issue isn't reproducable on windows.

Hey guys, newbie linux user here.

I'm having issues with node_modules and npm.
Our project is built in React & Node, and it works fine on other people's Windows machines - but not on my local linux.

Basically, I have a package.json which contains a list of all the required dependencies and devDependencies for a project.
When you run "npm install" this installs all said dependencies into node_modules.

However, when I try and build the project with 'webpack --mode production' I get an error saying webpack was not installed. It is definitely there in devDependencies...but it's not (usually) in node_modules. It's like the computer doesn't know where to look. It's also completely indeterministic, and node_modules sometimes has webpack and sometimes doesn't.

Similarly, with the webpack configuration, webpack.config.js
Webpack is supposed to load HtmlWebpackPlugin, like so:
const HtmlWebpackPlugin = require('html-webpack-plugin').

But it can't find it! html-webpack-plugin is clearly defined in package.json, although it doesn't seem to be in node_modules..

I've tried quite a few things, including uninstalling and reinstalling nvm, node and npm - to no avail.

What does fix the error is if I move all the devDependencies to dependencies in package.json - but that's obviously not ideal for development.

I'm wondering if this has something to do with how linux finds files, but it's completely baffling me. Any help would be greatly appreciated.

Thanks!

pan64 04-12-2024 04:53 AM

in that case you might want to mark the thread solved.


All times are GMT -5. The time now is 07:23 AM.