Deploying Angular 9 ivy packages

Szórádi Balázs
2 min readMar 27, 2020

As you have by now probably found out it is not possible (allowed) to release ivy built packages to npm. Explanation for this on angular.io is the following:

If you are a library author, you should keep using the View Engine compiler as of version 9. By having all libraries continue to use View Engine, you will maintain compatibility with default v9 applications that use Ivy, as well as with applications that have opted to continue using View Engine.

The Angular team has stated that this issue will be addressed no sooner than version 10.

Many of us are in fact working on a private projects needing no compatilility with the legacy view engine, therefore we want to have our packages built by the ivy compiler, and not having to wait for version 10.

Luckily there is a workaround. When your library is built the generated package.json file of the library will conatin the following scripts section:

"scripts": {
"prepublishOnly": "node --eval \"console.error('ERROR: Trying to publish a package that has been compiled by Ivy. This is not allowed.\\nPlease delete and rebuild the package, without compiling with Ivy, before attempting to publish.\\n')\" && exit 1"
}

So all you have to do is to write a post build script to remove this script section from the generated package.json file before it is packed and deployed.

// removing prepublishOnly as aimple as:
sed -i '/prepublishOnly/d' package.json
// or using a script like:
try {
const pkg = require('./dist/my-lib/package.json');
delete pkg.scripts;
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
}
catch (err) {
console.log(`Ivy package fix failed: ${err}`);
process.exit();
}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Szórádi Balázs
Szórádi Balázs

Written by Szórádi Balázs

Programming in assembly, c, c++, java, javascript, typescript. Interested in 3d graphics, visual effects, demoscene, dsp, c64, cycling, climbing…

No responses yet

Write a response