Search code examples
node.jsnpmofflinenode-modulestsc

Command "npm run tsc" does not work in an offline machine - trying to compile node_modules libraries


I want to execute the following commands in an offline machine (A) but the seconds point does not work:

  1. npm install
  2. npm run tsc

We have a machine (A) that contains my TypeScript APP and another machine (B) that acts as Artifactory (contains all the npm dependencies).

The problem here:

  • I cannot connect the machine A to B due to proxy restrictions.

My idea was to install my TypeScript APP into another machine (C) that does not have proxy restrictions doing the following "steps" into machine C (machines A and C has the same Operative System):

  1. "npm install" (download the dependencies)
  2. "npm run tsc" (to verify everyting compile)
  3. TAR the folder "node_modules"
  4. Copy the TAR from machine C to A
  5. Untar "node_module.tar" as "node_module" folder

The problem here is after executing "npm run tsc" into machine A there are a lot of "node_modules" ERRORs and I don't understand why. I share with you three example of hundreds of them:

node_modules/rxjs/Scheduler.d.ts(53,67): error TS1109: Expression expected.
node_modules/rxjs/Scheduler.d.ts(53,83): error TS1109: Expression expected.
node_modules/rxjs/Scheduler.d.ts(53,86): error TS1005: ';' expected.

FYI - I could change the machine A to be online temporary and "npm install" + "npm run tsc" worked properly. Then, I think there is something bad in the previous "steps".

Info about my installations:

bash-4.2# npm -v
3.10.10
bash-4.2# node -v
v6.9.5
bash-4.2# tsc -v
Version 1.8.10

Many thanks!


Solution

  • I finally found the issue in "node_modules" folder.

    It turns out that:

    • When I created the TAR file, the compressed files were not export with the "Linux links" to other files.
    • This issue happened into the folder "node_modules/.bin". This folder contains "Linux links" to other files that belong to "node_modules" subfolders.
    • In my case, there is a link named as "node_modules/.bin/tsc that was not exported with link inside the TAR.
    • On the other hand, after uncompressing the TAR, the referenced file "node_modules/typescript/bin/tsc" was copied without execution permission (644).
    • Although the Linux link was fixed, the execution permission was disabled, then I have to change the permissions to 755.

    Then, the steps to fix it were the following (inside "node_modules") folder:

    • rm .bin/tsc
    • ln -s ../typescript/bin/tsc tsc
    • chmod 744 typescript/bin/tsc

    Cheers, Paco.