searched closed issues for solution(s) or feedback
Current behavior
the default export is not available when running the project as a commonjs module:
class Exception extends import_aggregate_error_ponyfill.default {
^
TypeError: Class extends value #<Object> is not a constructor or null
at Object.<anonymous> (/Users/lex/Desktop/exceptions/dist/exceptions/base.exception.cjs:39:57)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/lex/Desktop/exceptions/dist/exceptions/index.cjs:32:27)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
Reproduction
git clone https://github.com/flex-development/exceptions ~/Desktop/exceptions
cd~/Desktop/exceptions
git checkout 5406594fe0722c3c3780eef5ef1f41cbcca50a54
yarn
yarn add @flex-development/[email protected]
yarn build
node dist/index.cjs
/Users/lex/Desktop/exceptions/dist/exceptions/base.exception.cjs:39
class Exception extends import_aggregate_error_ponyfill.default {
^
TypeError: Class extends value #<Object> is not a constructor or null
at Object.<anonymous> (/Users/lex/Desktop/exceptions/dist/exceptions/base.exception.cjs:39:57)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/lex/Desktop/exceptions/dist/exceptions/index.cjs:32:27)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
Setting "type": "module" in your package.json means "I need to use node's behavior" for both Webpack and esbuild. If you don't need node's behavior, then just remove "type": "module" from your package.json.
unfortunately, this logic does not account for needing "type": "module" in development (e.g. running tests + running scripts in package.json), but not when building commonjs modules. toggle-pkg-type was created to circumvent this issue, however. it is a cli tool that can disable and enable type in package.json. it should be used in the project's build script: