close

Filter

loading table of contents...

Frontend Developer Manual / Version 2107

Table Of Contents

5.16 Using Npm Instead of Yarn

If for whatever reasons you do not want to install and use yarn during development, CoreMedia currently still supports development using npm instead of yarn but CoreMedia might drop the support for npm in one of the next releases.

Caution

Caution

The following paragraphs only apply if you do not want to use yarn during development. Just skip this section if you will use yarn (which is our recommended approach).

Warning

Warning

If you are using NPM instead of yarn, the yarn.lock is no longer taken into account. The lock file guarantees that the same dependency versions are installed every time so a consistent build behavior is achieved.

Changing to NPM means you will lose the consistent build behavior so you will do this at your own risk.

To run scripts for multiple package inside a workspace and to retain support for npm as a package manager a tool named lerna (see https://lerna.js.org/) is used. It will be installed via the package.json of the frontend workspace and supports a similar workspace concept that yarn has already built-in.

In order to switch to npm you need to perform the following steps:

  • First of all you need to install the workspace using npm install. This will install the necessary dependencies for the frontend workspace (including lerna) but in contrast to yarn it will not install the inner packages as npm does not have any support for workspaces.

  • After the root package has been installed using npm, you need adjust the configuration for lerna in the package.json which can be found in the root directory of the workspace. Change the value of the entry npmClient from yarn to npm.

  • Now you can run the command npm run lerna bootstrap in the shell to install all inner packages of the workspace.

Caution

Caution

Do not install any package other than the root package of the workspace using npm install you need to use npm run lerna bootstrap to update the workspace, otherwise the installation files of the workspace might be corrupted.

If you have installed any inner package of the workspace using yarn or npm you might need to run npm run lerna clean first to make sure that the node_modules folder is cleaned up, otherwise npm might not be able to run the installation.

When adding dependencies to any package inside the frontend workspace you may use neither npm install --save dependency-name nor npm add dependency-name but npm run lerna add dependency-name --scope package-name. The same applies to other modifications to dependencies using the command line. Please read the Lerna documentation for additional information.

After directly editing entries in the package.json of any package inside the frontend workspace make sure to run npm run lerna bootstrap again.

Besides the limitations regarding the installation of packages every yarn command mentioned in the documentation can also be used with npm (just replace 'yarn' by 'npm') as both tools share the same commands in most of the cases.

If you need to configure a proxy for the npm registry follow the steps in Section 5.14, “Running YARN Behind a Proxy Server” using npm instead of yarn commands and http://registry.npmjs.org/ as the registry URL.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.