Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Jest error: is-plain-obj: SyntaxError: Unexpected token 'export' #10523

Closed
gigitux opened this issue Aug 10, 2023 · 0 comments · Fixed by #10788
Closed

Jest error: is-plain-obj: SyntaxError: Unexpected token 'export' #10523

gigitux opened this issue Aug 10, 2023 · 0 comments · Fixed by #10788
Assignees
Labels
type: bug The issue/PR concerns a confirmed bug. type: refactor The issue/PR is related to refactoring.

Comments

@gigitux
Copy link
Contributor

gigitux commented Aug 10, 2023

Describe the bug

There is an issue with the current dependencies tree. If the package-lock.json and node_modules are deleted, and the dependencies are reinstalled, Jest will not be able to run tests anymore. This is the error:

woocommerce-gutenberg-products-block/node_modules/is-plain-obj/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export default function isPlainObject(value) {
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

image

This is the output of the npm ls is-plain-obj. On the right, the dependencies tree with the current package-lock, on the left the dependencies tree with a new installation without package-lock.json.

As you can see, the @wordpress/data package uses is-plain-obj@4.1.0 that contains the ES Module on a new installation.

Searching online, I found this PR on Gutenberg repo. I think the best solution is to upgrade all the @wordpress/* dependencies. We should do this after the webpack 5 migration.

To reproduce

Steps to reproduce the behavior:

  1. Remove package-lock.json and node-modules.
  2. Run npm install.
  3. Run npm run test.
  4. See error.

Expected behavior

Unit tests should run.

@gigitux gigitux added type: bug The issue/PR concerns a confirmed bug. type: refactor The issue/PR is related to refactoring. labels Aug 10, 2023
@samueljseay samueljseay self-assigned this Aug 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug The issue/PR concerns a confirmed bug. type: refactor The issue/PR is related to refactoring.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants