Missing source files when building package installed from GitHub
I'm running into an issue where the build script is failing for a package that is installed via git/github. The error message looks like this:
> [email protected] postinstall /Users/clay/dev/code/tmp/postinstall-test/node_modules/angular2-token
> postinstall-build lib --script=build --verbose
> [email protected] prepublish /Users/clay/dev/code/tmp/postinstall-test/node_modules/angular2-token
> npm run build
> [email protected] build /Users/clay/dev/code/tmp/postinstall-test/node_modules/angular2-token
> rimraf lib && ngc -p src
Error: ENOENT: no such file or directory, lstat 'src'
at Object.fs.lstatSync (fs.js:947:11)
at Object.main (/Users/clay/dev/code/tmp/postinstall-test/node_modules/angular2-token/node_modules/@angular/tsc-wrapped/src/main.js:59:21)
at main (/Users/clay/dev/code/tmp/postinstall-test/node_modules/angular2-token/node_modules/@angular/compiler-cli/src/main.js:19:16)
at Object.<anonymous> (/Users/clay/dev/code/tmp/postinstall-test/node_modules/angular2-token/node_modules/@angular/compiler-cli/src/main.js:35:5)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Function.Module.runMain (module.js:609:10)
Compilation failed
This only fails when I'm trying to install from Git:
npm i --save MadeByMunstersLLC/angular2-token#fix_postinstallIssue
When the installation is from my local repo, it works perfectly fine:
npm i --save /path/to/MadeByMunstersLLC/angular2-token
The postinstall and build scripts for the (forked) angular2-token project are pretty straightforward:
"scripts": {
"test": "karma start",
"build": "rimraf lib && ngc -p src",
"prepublish": "npm run build",
"postinstall": "postinstall-build lib --script=build --verbose"
},
I've tried with a number of different npm versions, and each results in the same error. I forgot to keep track of exactly which versions, but IIRC they included 5.4, 5.3, 4.6, 4.2, and 3.10. I've reverted to node 8.4.0 and npm 5.3.0, where I'm still seeing the problems.
Seems like this issue might be similar (or identical) to #16, but that issue doesn't mention the package source, and as that seems to be playing a significant role in determining where postinstall-build can work with npm to successfully build a package, I figured I'd open up this new issue.
Any thoughts on this build error?
I had this same problem but then I realized that I have my src/ inside my .npmignore file.
According to: https://www.npmjs.com/package/postinstall-build#excluding-source-files-via-npmignore-or-files
Excluding source files via .npmignore or files
When npm installs from a Git repository or any other non-package location, it will first prepare the directory as if it were publishing a package. This includes respecting the .npmignore file and files field in package.json, which means that postinstall scripts may be executed with a subset of the files you need to run your build step. Thus, in order for postinstall-build to work, you should not ignore the source files or any necessary configuration (for example, .babelrc).
This is not ideal, but it’s how npm works. If you are determined to exclude unnecessary source and configuration files from the published npm package, you may want to consider a publishing step that alters the .npmignore or files settings.
So, maybe you have `src/' in your .npmignore?