Exceptionless.JavaScript icon indicating copy to clipboard operation
Exceptionless.JavaScript copied to clipboard

Can't Use exceptionless/react on Next.js project

Open polluterofminds opened this issue 4 years ago • 3 comments

When trying to import the @exceptionless/react package in Next.js, the following error occurs:

SyntaxError: Named export 'fromError' not found. The requested module 'stacktrace-js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'stacktrace-js';
const { fromError } = pkg;

Steps to reproduce:

  1. npx create-next-app app-name
  2. npm i @exceptionless/react
  3. in pages/index.js add the import line at the top: import { Exceptionless } from "@exceptionless/react";

polluterofminds avatar Sep 01 '21 12:09 polluterofminds

@polluterofminds Did you enable esm support as described here: https://nextjs.org/blog/next-11-1#es-modules-support

niemyjski avatar Sep 02 '21 13:09 niemyjski

Just tested this, and I get the same error. Looks like this is a known Next.js issue: https://github.com/vercel/next.js/issues/25454

polluterofminds avatar Sep 03 '21 12:09 polluterofminds

Did their fix solve this? I think we need to bring in stacktrace.js and convert it to be 100% esm

niemyjski avatar Sep 03 '21 14:09 niemyjski

I just confirmed this is still broken in 2.0.1 but is fixed in main! I tested it by running npm install --save ../Exceptionless.JavaScript/packages/react

niemyjski avatar Mar 01 '23 03:03 niemyjski