Quirks
Having trouble? Here are some known (mostly npm related) quirks and suggestions on how to work around them that might help.
-
It’s recommended to have
elm-toolingin"devDependencies"inpackage.json. That makes sense since you only needelm-toolingfor development and building your application, not at runtime in production. But, this has the consequence thatnpm install --production/npm ci --productionwill fail. Why? Because the"postinstall"script will still execute, and try to runelm-tooling install– butelm-toolingisn’t even installed ("devDependencies"is ignored when using the--productionflag). So what are your options?- Maybe you don’t even need
--production. Some applications usenpmonly for a build step and does not have any production Node.js server or anything like that. - Try
--ignore-scripts. This will skip the"postinstall"script – but also any scripts that your dependencies might run during installation! Sometimes, only"devDependencies"(such as node-sass) need to run scripts during installation – so try it! If--ignore-scriptsworks you have nothing to lose. - Make a little wrapper script that runs
elm-tooling installonly ifelm-toolingis installed. For example, you could write the script in JavaScript and use the API version of the CLI. - If you only need
--productioninstalls in for example a Dockerfile, try addingRUN sed -i '/postinstall/d' package.jsonto remove the"postinstall"script frompackage.jsonbefore runningnpm install --production. This specific example only works with GNU sed and if your"postinstall"script isn’t last (due to trailing commas being invalid JSON). - Move
elm-toolingto"dependencies".elm-toolingis small and has no dependencies so it won’t bloat your build very much. Set theNO_ELM_TOOLING_INSTALLenvironment variable to turnelm-tooling installinto a no-op (see below).
- Maybe you don’t even need
-
If you’re using
npm’s ignore-scripts setting, that also means your ownpostinstallscript won’t run. Which means that you’ll have to remember to runnpm run postinstallornpx elm-tooling installyourself.npmtends to keep stuff innode_modules/.bin/even when runningnpm ci(which claims to removenode_modules/before installation), so it should hopefully not be too much of a hassle. -
You can set the
NO_ELM_TOOLING_INSTALLenvironment variable to turnelm-tooling installinto a no-op. This lets you runnpm installwithout also runningelm-tooling install, which can be useful in CI. -
If you’re creating an npm package that uses
elm-toolingto install Elm and other tools during development, beware that"postinstall": "elm-tooling install"will run not only when developers runnpm installin your repo, but also when users install your package withnpm install your-package! You can solve this by using"prepare": "elm-tooling install"instead. prepare also runs afternpm installin development, but not afternpm install your-package. However, it also runs beforenpm publish, which unneeded but doesn’t hurt that much since it’s so fast after everything has been downloaded once.Another way is to generate the package.json that actually ends up in the npm package during a build step – a package.json without
"scripts","devDependencies"and other config that is only wasted bytes for all users of your package. -
This page used to be longer when npm 6 was the latest npm version. npm 6 is no longer supported for quite some time, so I strongly recommend updating!