Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve Chicken/Egg situation with `tsc` and `npm install`?

So I have the standard folder structure

dist/
src/

where src has my .ts files and dist has my .js files. (I have "outDir":"dist" in my tsconfig.json file, and "includes" set to 'src').

Note that 'dist' is in my gitignore file, so it is not in version control, and so when it goes to Travis or CircleCI, nothing is in the dist folder until I run tsc.

Here is the problem - if I run npm install first - it will fail because I have this in my package.json:

"bin":{
  "foo" :"dist/cli.js"   // dist/cli.js does not exist yet
}

but if I run tsc first - tsc will then be missing dependencies that it needs for compilation, which arrive if I run npm install.

The only thing I can think of to solve this, is to install all the necessary tsc dependencies first, then run tsc, then run npm install --production.

However that is not the most convenient thing to do.

Has anyone run into this problem and found a good solution?

like image 542
Alexander Mills Avatar asked May 31 '18 03:05

Alexander Mills


People also ask

How do I fix npm installation errors?

If your npm is broken: On Mac or Linux, reinstall npm. Windows: If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer (see this note about installing the latest stable version).

What to do when npm install gets stuck?

Remove node_modules and package-lock. To solve the issue, try removing the entire node_modules/ folder and the package-lock. json file. Then try running the npm install command again. That may fix the issue.

How do I resolve npm start error?

To solve the npm ERR! Missing script: "start" error, make sure to add a start command to the scripts object in your package. json file and open your shell or IDE in the root directory of your project before running the npm start command.

How do I get rid of npm warnings?

you need to change that to npm --logevel=error install , and that will suppress the WARN message and Team Foundation Server will stop complaining about it. After waiting on angular 4 to install for an hour, I cancelled it, used this parameter, and it installed in about 10 seconds.


1 Answers

I don't remember having this problem but in at least one case I did something that will work around the issue.

I put an index.js in the root folder that runs the actual dependency in dist. Then the bin that npm looks for is a file that's present, and it shouldn't freak out.

It won't work until tsc is run, of course. But it should resolve your chicken and egg problem.

like image 79
SomeCallMeTim Avatar answered Sep 19 '22 22:09

SomeCallMeTim