sorin
sorin

Reputation: 170508

How to correctly compile a nodejs package before installing it?

I am trying to fix a bug in a cspell package which fails to install from git clone and I am facing a conundrum.

I found that the installation expects to copy files from dist/ folder which does not exist in a clean clone because is produced by running npm compile

So I decided to add this into package.json scripts section:

"preinstall": "npm run compile"

Mainly before running install, it should run compile, which I know to be producing the desired files.

Now I faced a new problem: compile fails because of missing "tsc" command. I looked and apparently this is provided by typescript package which was listed as a devDependency. Because it was missing i suspected that it was not installed because install was supposed to install only runtime dependencies and I decided to try to move it there. Bad luck, doing this was not enough, which means that preinstall is run before installing any dependencies.

What is the magic needed for fixing installation from source, without adding extra manual steps between clone and install command?

Upvotes: 2

Views: 110

Answers (1)

hong4rc
hong4rc

Reputation: 4113

You should install global for typescript.

Or create script postinstall run before start main script but after install all package.

Upvotes: 1

Related Questions