5

I have a build script in javascript project that uses parcel to iterate through folders and finding index files and then building those projects. When I find an index file I run this command:

npx parcel build ${indexFilePath} --out-dir ${outDir} --target node

But, if the person running this build script has not installed packages with npm i yet, the npx command will install the latest version of parcel-bundler, where --out-dir is now deprecated and breaking the entire script.

Here is what's going on, distilled:

$ rm -rf node_modules
$ npm i
$ npx parcel --version
1.12.4
$ rm -rf node_modules
$ npx parcel --version
2.0.0-beta.2

Is there any option for npx to use the version in the package.json file that is already in the project and install it to node_modules? Or do I just ingrate the install step into my build? It just seems overkill, since all I need to build is parcel.

Am I abusing npx by using it like this?

jokarl
  • 1,913
  • 2
  • 24
  • 52

1 Answers1

3

Multiple issues exist in npx regarding this problem : #199 & #15

The only option I found so far was to parse & extract version from my package.json using node repl (which should be available in your case)

Something like this :

npx parcel@`node -p -e "require('./package.json').dependencies['parcel']"` --version
Frédéric Camblor
  • 1,301
  • 2
  • 12
  • 22
  • Thanks for the heads up, I'll follow those issues. I ended up extracting version from package.json with `jq`, but I prefer this solution. – jokarl Apr 14 '22 at 13:45