prepare script isn't executed when installing from git source

What I Wanted to Do

Wanted to install CLI app from git repo globally that needs to be transpiled with babel.

I ran
npm install -g AlexanderProd/kurly

What Happened Instead

The postinstall script inside the package.json wasn’t executed and therefore the bin file couldn’t be found and this error was returned.

npm ERR! path /usr/local/lib/node_modules/kurly/dist/index.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/kurly/dist/index.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alexanderhoerl/.npm/_logs/2018-12-13T12_44_08_743Z-debug.log

Reproduction Steps

Try to globally install this repository

Details

2018-12-13T12_44_08_743Z-debug.log (15,5 KB)

Platform Info

$ npm --versions
{ npm: '6.4.1',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.33.0',
  node: '10.11.0',
  openssl: '1.1.0i',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.0',
  v8: '6.8.275.32-node.28',
  zlib: '1.2.11' }

$ node -p process.platform
darwin

postinstall is not the script you’re looking for. Use prepare instead.

I’ve tried prepare too, but It didn’t work either. Also as far as i understood it prepare is triggered before uploading to npm. But I want to be able to install the package from a git source.

prepare is executed when installing a package from git sources, if that package has a prepare script defined. (on recent versions of npm)

I’ve just tried to install this package with a prepare script in in its package.json from git source using
npm install -g https://github.com/AlexanderProd/kurly.git

But I still get this error.

npm ERR! path /usr/local/lib/node_modules/kurly/dist/index.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/kurly/dist/index.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alexanderhoerl/.npm/_logs/2018-12-15T07_40_29_606Z-debug.log

So it seems like the prepare script didn’t work
because it would have created the dist/index.js file using Babel.
I’m using npm version 6.4.1

Can you take a look at the repository to see if everything is correct, otherwise i guess there’s a bug with the script tag.

When installing the package globally using yarn the prepare script is being executed, therefore I’ve changed the category to bugs. I’ve also tried it with the latest npm version 6.5.0 but the prepare script still isn’t executed.

I think (haven’t been able to check yet) the script is scheduled to run, but only after the bins are resolved. I suppose Yarn does that differently.

Then It would make sense that it doesn’t work, but this should be changed then. Otherwise you couldn’t install global packages that need to be compiled from github.

For all Git repos with bin fiels actually. Solving it is a bit more difficult, I think:

  • The build action is, among other things, responsible for linking binaries.
  • That depends on dist/index.js existing,
  • but that file is only created when the prepare script is run,
  • which is run in pacote (I haven’t been able to find the exact action yet, but after build).
  • However, that prepare scripts needs a linked binary (babel)…

Edit

I suppose it’s the other build action in babel that is needed for extract, then, thanks for the clarification.

Thanks for explaining this. Is there even another way than uploading a compiled file to GitHub then though?

prepare is run inside a separate npm run inside extract, by opts.dirPacker.

Looking at the code, git deps are installed like this (AFAICT):

  • clone into cache/tmp
  • install sub-dependencies
  • run prepare
  • pack the package
  • move to node_modules (maybe .staging, still not really sure what that is)
  • unpack

It looks like packDirectory just doesn’t pack dist because it’s in .gitignore.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.