I am facing an issue with using a library in Angular, specifically the cubing npm package. This library is designed to run in both the browser and node environments, with specific code for each. I want it to run in the browser, but when compiling with Angular, it fails to find worker_threads
. The library owner suggested ignoring this import as it's only needed for the node variant of the code.
However, I'm struggling to figure out how to make Angular ignore this import from the node module. How can I instruct Angular to disregard this import since we won't be using the code that requires it?
Error: Can't resolve 'worker_threads' in REDACTED/node_modules/cubing/dist/esm
If there's no direct solution, I might have to resort to patching the node_modules, but I'm hesitant about doing so due to potential challenges in getting it to work in production environments.
For additional context, here is the GitHub project (switch to branch scrambles for the issue at hand): https://github.com/Lykos/cube_trainer.git
Below are the most relevant files:
Package.json:
{
"name": "cube-trainer",
"private": true,
"author": "Bernhard F. Brodowsky",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/Lykos/cube_trainer.git"
},
"engines": {
"node": "16.x",
"npm": "8.x"
},
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --configuration production",
"build_development": "ng build --configuration development",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"test_ci": "ng test --karma-config client/karma-ci.conf.js",
"lint": "ng lint"
},
...
}
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
...
}
tsconfig.json
{
...
}
tsconfig.app.json
{
...
}