Module not found: Error: Can't resolve 'assert'
Description
After installing timezone-mock and importing it in a Karma/Jasmine test file, the Angular CLI build fails with a module resolution error for the Node core module assert. This appears to be caused by timezone-mock's internal use of assert, which is no longer auto-polyfilled by Webpack 5 (used internally by the modern Angular CLI builder).
Error
./node_modules/timezone-mock/index.js:3:13-30 - Error: Module not found: Error: Can't resolve 'assert' in '/Users/mfrede/Developer/ruby/frontend/node_modules/timezone-mock'
Steps to Reproduce
- Install
timezone-mock (v1.4.3) as a dev dependency
- Import and use it in a Karma/Jasmine spec file:
import timezoneMock from 'timezone-mock';
beforeEach(() => {
timezoneMock.register('US/Pacific');
});
afterEach(() => {
timezoneMock.unregister();
});
- Run the Angular/Karma test build
- Observe the build failure above
Environment
timezone-mock: 1.4.3
@angular/common: 21.0.9
- Node.js: v22.18.0
jasmine-core: 5.8.0
karma-chrome-launcher: 3.2.0
karma-jasmine: 5.1.0
- Build tool: Angular CLI (Webpack 5–based builder)
Expected Behavior
timezone-mock should be usable in a standard Angular CLI / Karma test setup without requiring manual Node core module polyfill configuration, since Webpack 5 no longer polyfills Node built-ins by default and most front-end frameworks (Angular CLI included) don't expose easy resolve.fallback overrides.
Possible Cause
index.js (or another internal file) appears to require('assert') unconditionally. If assert is only used for internal sanity checks (not user-facing functionality), it may be removable, made optional, or replaced with lightweight manual checks to avoid the Node core dependency entirely in browser/bundler contexts.
Workarounds Tried
installing assert manually creates new errors I could not really decipher
Chrome 148.0.0.0 (Mac OS 10.15.7) ERROR
An error was thrown in afterAll
Uncaught ReferenceError: process is not defined
ReferenceError: process is not defined
at Object.3245 (http://localhost:9876/_karma_webpack_/webpack:/node_modules/util/util.js:109:1)
at require (http://localhost:9876/_karma_webpack_/webpack:/webpack/bootstrap:25:1)
at Object.3770 (http://localhost:9876/_karma_webpack_/webpack:/node_modules/assert/build/internal/assert/assertion_error.js:25:16)
at require (http://localhost:9876/_karma_webpack_/webpack:/webpack/bootstrap:25:1)
at Object.24 (http://localhost:9876/_karma_webpack_/webpack:/node_modules/assert/build/assert.js:39:22)
at require (http://localhost:9876/_karma_webpack_/webpack:/webpack/bootstrap:25:1)
at Object.3099 (http://localhost:9876/_karma_webpack_/webpack:/node_modules/timezone-mock/index.js:3:14)
at __webpack_require__ (http://localhost:9876/_karma_webpack_/webpack:/webpack/bootstrap:25:1)
at Module.6095 (http://localhost:9876/_karma_webpack_/main.js:2107:71)
at __webpack_require__ (http://localhost:9876/_karma_webpack_/webpack:/webpack/bootstrap:25:1)
Additional Context
This only affects the test/build pipeline (Karma test bundle via Angular CLI); not yet confirmed whether it affects other bundlers or Node-only usage.
Module not found: Error: Can't resolve 'assert'
Description
After installing
timezone-mockand importing it in a Karma/Jasmine test file, the Angular CLI build fails with a module resolution error for the Node core moduleassert. This appears to be caused bytimezone-mock's internal use ofassert, which is no longer auto-polyfilled by Webpack 5 (used internally by the modern Angular CLI builder).Error
./node_modules/timezone-mock/index.js:3:13-30 - Error: Module not found: Error: Can't resolve 'assert' in '/Users/mfrede/Developer/ruby/frontend/node_modules/timezone-mock'Steps to Reproduce
timezone-mock(v1.4.3) as a dev dependencyEnvironment
timezone-mock: 1.4.3@angular/common: 21.0.9jasmine-core: 5.8.0karma-chrome-launcher: 3.2.0karma-jasmine: 5.1.0Expected Behavior
timezone-mockshould be usable in a standard Angular CLI / Karma test setup without requiring manual Node core module polyfill configuration, since Webpack 5 no longer polyfills Node built-ins by default and most front-end frameworks (Angular CLI included) don't expose easyresolve.fallbackoverrides.Possible Cause
index.js(or another internal file) appears torequire('assert')unconditionally. Ifassertis only used for internal sanity checks (not user-facing functionality), it may be removable, made optional, or replaced with lightweight manual checks to avoid the Node core dependency entirely in browser/bundler contexts.Workarounds Tried
installing assert manually creates new errors I could not really decipher
Additional Context
This only affects the test/build pipeline (Karma test bundle via Angular CLI); not yet confirmed whether it affects other bundlers or Node-only usage.