Learn how to make the backend of your commercetools Frontend project compatible with Node.js 18.
Copy for LLM
View as Markdown
commercetools Frontend projects are created to be compatible with Node.js 18. However, your existing project may not be compatible with it. In such case, follow the instructions on this page to migrate your project's backend to Node.js 18.x.
Make backend compatible with Node.js 18
Follow these steps to make your webpack-built Node.js 12.x-16.x project compatible with Node.js 18.x:
-
Remove the webpack-related configuration by deleting the
webpackfolder at this pathpackages/PROJECT_NAME/backend/webpack. -
Delete the webpack-related packages by running the following command in the
packages/PROJECT_NAME/backenddirectory:yarn remove webpack webpack-cli webpack-merge ts-loader babel-loader dotenv-webpack.
Also, delete any other packages you added for your webpack configuration. You should install esbuild plugins to replace the packages you deleted. -
Add tsup version 7.2.0 by running the following command in the
packages/PROJECT_NAME/backenddirectory:yarn add -D tsup@7.2.0. -
Add tsup configuration by adding the following
tsup.config.tsfile topackages/PROJECT_NAME/backend.import { defineConfig } from 'tsup'; import { BuildOptions } from 'esbuild'; export default defineConfig((options) => { const dev = options.env?.['NODE_ENV'] === 'dev'; return { entry: ['index.ts'], outDir: undefined, esbuildOptions: (options: BuildOptions) => { options.outfile = 'build/bundle.min.js'; }, sourcemap: true, watch: dev, noExternal: [/(.*)/], }; }); -
Edit the
package.jsonfile at this pathpackages/PROJECT_NAME/backend/package.jsonas follows:-
Set the value of
engines.nodeto16.14 - 18.x.18.x is the recommended Node.js version. Using other versions greater than or equal to 16.14 is still supported but not recommended.
The16.14 - 18.xrange is related to the compatibility of tsup version 7.2.0. -
Set the value of
scripts.extensions:watchtotsup --env.NODE_ENV dev. -
Set the value of
scripts.buildtotsup.
{ ... "engines": { "node": "16.14 - 18.x" }, "scripts": { "extensions:watch": "tsup --env.NODE_ENV dev", "build": "tsup", ... } } -
Caveats and potential issues
Compilation error in Contentful
Some projects were created with versions of Contentful that have issues in their types, specifically version
9.3.5.If you experience any issues, check Contentful version in the
yarn.lock file at this path packages/PROJECT_NAME/backend/yarn.lock or by running the yarn why contentful command:- If the version is not
9.2.5, install Contentful version9.2.5by running therun yarn add contentful@9.2.5command or by editing the version in theyarn.lockfile. - If version is
9.2.5, contact Support.
Compilation error in string-width, strip-ansi, or wrap-ansi
Some projects were created with a deep dependency of the
string-width, strip-ansi, or wrap-ansi packages that causes errors during compilation. This can manifest as an error in one of the mentioned packages.If you experience any issues, add the following resolutions to the
package.json file at this path packages/PROJECT_NAME/backend/package.json."resolutions": {
"string-width": "4.2.2",
"strip-ansi": "6.0.1",
"wrap-ansi": "7.0.0"
}