Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] tslog loads Node.js runtime in a browser environment when used as a transitive dependency #305

Open
wujekbogdan opened this issue Sep 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@wujekbogdan
Copy link

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

@wujekbogdan wujekbogdan added the bug Something isn't working label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant