0

Our team is getting an export syntax error only when running the mocha tests after including a particular library (Bryntum Scheduler in this case). We are able to reproduce the issue in this sample project: https://github.com/eduardofavarato/bryntum-scheduler-mocha-ts-sample

Error in question:

/frontend/node_modules/@bryntum/scheduler-react/lib/index.js:1
export * from './BryntumFullscreenButton';
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)

Any ideas why? I think it could be related to commonjs vs esmodule discrepancy but not sure. I also shared the problem with the Bryntum team but haven't heard back yet on a resolution.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Owlstack
  • 11
  • 2
  • This doesn't have anything to do with mocha. You're probably using some kind of bundler or transpiler that's not set up to deal with what this library is giving it. Are you using webpack? – Halcyon Sep 05 '22 at 20:24
  • Hi yes, we are using webpack. In this example, we don't even have webpack ejected like we do in our main project but we can still reproduce the issue: https://github.com/eduardofavarato/bryntum-scheduler-mocha-ts-sample – Owlstack Sep 05 '22 at 20:27
  • 2
    It seems to me like you're using the `cjs/loader` (commonjs) to load a library that is not built as a commonjs library (probably esmodule, like you say). Figure out why your webpack is using the wrong loader. – Halcyon Sep 05 '22 at 20:37
  • How do I figure out why my webpack is using the wrong loader? Is there a way to specify specific loaders? One other thing is this post which suggests the library maintainer actually update their library to add the type module in their package.json. Is this the right approach? https://stackoverflow.com/questions/70914025/jest-syntaxerror-unexpected-token-export . The issue with running the mocha tests only appeared after importing this library – Owlstack Sep 05 '22 at 21:51
  • The scope of this question has surpassed what I can do for you on stackoverflow. You're going to have to get stuck in to fix this. It's probably going to take a lot of trial and error. – Halcyon Sep 05 '22 at 22:02
  • It already has to be honest. Our team moved to Jest because of this issue and another user had a similar issue here: https://stackoverflow.com/questions/52524764/jest-mocha-typescript-jest-mocha-tries-to-read-js-dependencies-and-fails-u The only thing that helped was migrating to Jest which worked with the solution above but significantly impacted the performance of our tests. So we're working to resolve it with Mocha. – Owlstack Sep 06 '22 at 00:58
  • Fire the guy who wrote [this line](https://github.com/eduardofavarato/bryntum-scheduler-mocha-ts-sample/blob/b3424b6e523d496bd4862cfac3cb20da3e1380ae/tsconfig.json#L11). – hackape Sep 06 '22 at 01:19
  • Joke aside, have you even tried to understand how your script work? If you follow `packageJson.scripts.test`, you’ll see no webpack involved in the process, only `tsc`, which doesn’t do bundling and only transform the source code you write, not node_modules. – hackape Sep 06 '22 at 01:24
  • @hackape What's wrong with the module: commonjs line? Also, do I need to transform the node_modules line as well in order to get transpilation support for the library? – Owlstack Sep 06 '22 at 01:32
  • Line above it says `//"module": "esnext", //bryntum`. Should uncomment and use it. I don’t know if you should transform node_modules, it depends on whether included package is executable in nodejs. – hackape Sep 06 '22 at 02:14
  • Since `@bryntum/*` scope packages are private, I can’t look into details. But it seems to me this bryntum thing is paid software came with tech support, why don’t you ask them to look into your pb? – hackape Sep 06 '22 at 02:22
  • We did. They have not responded until just now and their response has not been helpful at all. Their support model isn't very good: https://www.bryntum.com/forum/viewtopic.php?p=110136#p110136 :(( – Owlstack Sep 06 '22 at 16:26
  • @hackape would it help if I shared their package.json file or anything else from their repo? I believe you can see the content however if you sign up for free trial. – Owlstack Sep 06 '22 at 16:28
  • @Owlstack Were you able to find a solution to your issue? – Mats Bryntse Nov 19 '22 at 17:49

0 Answers0