Error while running tests with unist-builder version 3.0.0
LokeshNSF opened this issue · 1 comments
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
Affected packages and versions
3.0.0
Link to runnable example
No response
Steps to reproduce
Using jest for running the test throws error for unist-builder version 3.0.0. The same used to work fine for 2.0.3 version,
Error below,
Details:
/Users/lokeshkumar.n/mine/sandbox/doc-framework-monorepo/packages/@salesforcedocs/markdown-compiler/node_modules/unist-builder/index.js:16
export var u = /**
^^^^^^
SyntaxError: Unexpected token 'export'
3 |
> 4 | import {u} from 'unist-builder';
| ^
This is the error from Jest,
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
I tried configuring transform option for unist-builder to use babel-jest, but still same problem persists for version 3.0.0
Expected behavior
Tests should be able to use the version 3.0.0
Actual behavior
Throws error while running tests using jest.
Runtime
Node v14
Package manager
yarn v1
OS
macOS
Build and bundle tools
Other (please specify in steps to reproduce)
Version 3 is packaged as standard ESM (JavaScript modules)
Some tools including Jest need to be configured to support this, this guide covers many tools.
For Jest particularly see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#im-having-problems-with-esm-and-jest and https://github.com/facebook/jest/blob/64de4d7361367fd711a231d25c37f3be89564264/docs/ECMAScriptModules.md