Description
Describe the bug
I created a logging library that uses tslog
under the hood. The library is compiled with tsc
(there's no bundling) and shipped as a CommonJS package. It works well in a Node.js environment, but it fails in the browser with the error: TypeError: (0 , util_1.formatWithOptions) is not a function
.
I'm not entirely sure what happens, but I suspect the following "browser"
entry from tslog's package.json
is being ignored:
"browser": {
"tslog": "./dist/browser/index.js",
"./dist/esm/runtime/nodejs/index.js": "./dist/esm/runtime/browser/index.js",
"./dist/cjs/runtime/nodejs/index.js": "./dist/cjs/runtime/browser/index.js",
"./src/runtime/nodejs/index.js": "./src/runtime/browser/index.js",
"util": false
}
As a result, the Node.js runtime is being used in the browser.
To Reproduce
- Create a package that uses
tslog
. - Compile it with
tsc
as a CommonJS module. - Publish the package and use it as a dependency in an app running in a browser environment.
- Instantiate the logger and call any logger method, such as
logger.info()
.
Expected behavior
The browser version of tslog should be used, without errors, in browser environments.
Screenshots
None
Additional context
I'm not sure if this is a bug in the library or if it's related to the fact that I'm shipping my module as CommonJS, where tsc
converts tslog
imports into require('tslog')
. If that's the case, please treat this bug report as a support ticket. Thanks!
Node.js Version
v18.14.2
OS incl. Version
Any