Skip to content

SyntaxError: Cannot use import statement outside a moduleΒ #9395

@caesaneer

Description

@caesaneer

When you use ECMAScript Modules in Node (v13.6.0 for me) combined with Jest, the following error occurs:

SyntaxError: Cannot use import statement outside a module

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)

Here is the test code I am trying to execute.

import { checks } from '../../../../src/utils/index.js'

describe('Array type check', () => {
    test('to return false when not an array', () => {
        expect(checks.array('string')).toEqual(false)
    })
})

I suspect the issue is Jest is not configured to run Node code using "type: module" (ECMAScript Modules).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions