gradle-node-plugin icon indicating copy to clipboard operation
gradle-node-plugin copied to clipboard

setting nodeModulesDir doesn't change node_modules path

Open jameshilliard opened this issue 5 years ago • 8 comments

When I set nodeModulesDir = file("${project.buildDir}") in my build.gradle the node_modules folder still ends up in ${projectDir} and not ${project.buildDir}.

jameshilliard avatar Dec 04 '19 10:12 jameshilliard

I just created a testcase and it seems to work as expected https://github.com/node-gradle/moved_node_modules

Though I'm guessing that you really want package.json in / and node_modules located in /build/node_modules but looking at https://docs.npmjs.com/files/folders.html it doesn't seem like that's how npm works.

deepy avatar Dec 04 '19 10:12 deepy

Though I'm guessing that you really want package.json in / and node_modules located in /build/node_modules

Yeah, that's what I was going for so that the node_modules for the gradle build wouldn't conflict with the one created if you run yarn directly.

Hmm, can NODE_PATH be used for forcing an alternate node_modules path? Yarn seems to at least be able to override it for the install using the --modules-folder flag but I couldn't figure out how to get the env set up properly for running scripts.

jameshilliard avatar Dec 04 '19 11:12 jameshilliard

It sounds like NODE_PATH would work slightly differently https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders

But why do you want them to be separate? is it really a conflict? I mean they're both building the same thing, so they should have the same result

deepy avatar Dec 05 '19 09:12 deepy

is it really a conflict?

So it's mostly an issue if the version of node being used by gradle differs from the one used when not using gradle as package c extensions seem to sometimes be version specific.

jameshilliard avatar Dec 05 '19 09:12 jameshilliard

It sounds like in your case you want download = false aka "use local node", that way you shouldn't have any mismatch.

If you don't have or want node on your CI environment you could do something like download = System.getenv().containsKey("CI") and set CI=true

deepy avatar Dec 05 '19 09:12 deepy

Well I was wanting to use the downloading feature for compilation of production asset bundles to ensure reproducibility. I only really wanted to use the local node for running webpack-dev-server.

jameshilliard avatar Dec 05 '19 09:12 jameshilliard

Hmm, I guess you could set nodeModulesDir to a directory in build, make the install task depend on a Copy task which copies your package.json there (along with the sources necessary to build the application).

But all-in-all it'd probably be easier to set up some CI to do the production build

deepy avatar Dec 05 '19 10:12 deepy

Is this issue fixed?

bsautel avatar May 08 '20 08:05 bsautel