Skip to content

SyntaxError: Cannot use import statement outside a module #3214

@mackwang112

Description

@mackwang112

In my github actions, executing npx eslint --ext .js,.ts,.tsx,.jsx packages/ resulted in the following error:

npx eslint --ext .js,.ts,.tsx,.jsx packages/

Oops! Something went wrong! :(

ESLint: 7.32.0

/home/runner/work/mpx/mpx/node_modules/eslint-plugin-import/node_modules/async-function/require.mjs:1
(function (exports, require, module, __filename, __dirname) { import getAsyncFunction from './index.js';
                                                              ^^^^^^

SyntaxError: Cannot use import statement outside a module
    at new Script (node:vm:117:7)
    at NativeCompileCache._moduleCompile (/home/runner/work/mpx/mpx/node_modules/eslint/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
    at Module._compile (/home/runner/work/mpx/mpx/node_modules/eslint/node_modules/v8-compile-cache/v8-compile-cache.js:184:36)
    at Module._extensions..js (node:internal/modules/cjs/loader:1623:10)
    at Module.load (node:internal/modules/cjs/loader:1266:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)
    at Module.require (node:internal/modules/cjs/loader:1289:19)
    at require (/home/runner/work/mpx/mpx/node_modules/eslint/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/home/runner/work/mpx/mpx/node_modules/eslint-plugin-import/node_modules/get-intrinsic/index.js:154:24)
    at Module._compile (/home/runner/work/mpx/mpx/node_modules/eslint/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)

Yesterday, it was still working normally, and even after I re-ran npm i locally, I couldn't reproduce the issue; it only occurs in my github actions.

I'm not sure who is calling async-function/require.mjs; theoretically, perhaps it should use async-function/index.js, but I'm not familiar with it.

Maybe this has nothing to do with eslint-plugin-import, but I have no idea where to start troubleshooting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions