Reproduction case for terser
error.
There are 3 yarn scripts available from anywhere in the project:
yarn resolve:terser <desired terser version>
yarn build-run:dev
yarn build-run:prod
Set the resolved terser version to <desired terser version>
.
Build and then run a non-minified (i.e. no terser used) bundle of @repro/main-package
with node
.
This is the control that the original code is not faulty, and that dependencies other than terser are not causing the error.
Build and then run a minified (by terser) bundle of @repro/main-package
with node
.
If the error occurs, the build is successful, but the run ends in a ReferenceError: BaseClass is not defined
runtime error.
The latest terser version that does not reproduce the error, is 5.15.0
. From 5.15.1
to 5.17.4
the error does happen.
Monorepo:
- Yarn 2 (berry) workspaces
- TypeScript, babel
- No build frameworks (lerna, nx, etc.)
This repo uses yarn plug-n-play.
Repo structure distinguishes
- main-package
- dependency-package
package.json in the top-level root directory:
{
...
"private": true,
"workspaces": [
"main-package",
"dependency-package"
],
...
}
To add a dependency to a workspace, and automatically adding its types to devDependencies, run yarn add <dep-name>
in
that workspace. Yarn's TypeScript plugin finds the dependency's @types
package, if it exists, and adds it to dev
dependencies automatically.
Some packages may not work with yarn's plug-n-play mode. To make them work, unplugging those packages can help.
This means that yarn will keep an unzipped version of a package, which comes closer to the node_modules
linker.
The base command is yarn unplug <package>
.
- The option
-R
will also unplug the package's dependencies recursively. - The option
-A
will unplug the package in every workspace that it's used in.
- Some eslint-related packages need to be unplugged for eslint to work on Windows.
- Use for type checking.
- Target ESNext in all configurations (code and module format).
- JavaScript code generation.
- Use babel to transpile for a specific target. -> by using webpack
{
...
"scripts": {
"type-check": "yarn run -T tsc --noEmit"
},
...
}
- Available from package
main-package
. - Type-checks all project code used directly or indirectly by said package.