admin管理员组

文章数量:1123349

I'm running eslint to control syntax for aws serverless project which has strict rules that causes failed deployments, the eslint itself is now causing the failed deployment with the error below. I've looked up the error and seen solutions that have included updating the parser and parserOptions but has not worked.

node: 16.20.2 eslint: 9.17.0 serverless: 3.4.2 @babel/eslint-parser: 7.25.9

Error: Parsing error: require() of ES Module /codebuild/output/src1416354794/src/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /codebuild/output/src1416354794/src/node_modules/babel-eslint/lib/require-from-eslint.js not supported. Instead change the require of definition.js in /codebuild/output/src1416354794/src/node_modules/babel-eslint/lib/require-from-eslint.js to a dynamic import() which is available in all CommonJS modules

As you can see below I have added the parser and parserOptions which have been the suggestions I have found when looking up the error but I am now stuck with what is causing the issue as nothing has changed the deployment still fails. Is there something I am missing?

Thanks in advance.

eslint.config/mjs

import globals from "globals";
import pluginJs from "@eslint/js";
import nodePlugin from "eslint-plugin-node";

/** @type {import('eslint').Linter.Config[]} */
export default [
  {languageOptions: { 
    globals: globals.browser,
    parser: "@babel/eslint-parser",
    parserOptions: {
      requireConfigFile: false,
      babelOptions: ["@babel/preset-env"],
      ecmaVersion: 2021,
      sourceType: "module",
    },
  }},
  pluginJs.configs.recommended,
  { 
    plugins: {
      node: nodePlugin,
    },
    files: ["src/**/*.js"],
    ignores: ['.webpack/**/*.js', 'node_modules/**/*.js', '.eslintrc.js'],
    rules: {
      'semi': ['error', 'always'],
      'no-unused-vars': 'warn',
      'no-undef': ['off'],
      'eqeqeq': 'error',
      'no-console': 'warn',
      'no-throw-literal': 'error',
      'no-async-promise-executor': 'error',
      'no-return-await': 'error',
      'no-eval': 'error',
      'no-new-func': 'error',
      'no-useless-escape': 'warn',
      'no-process-env': 'off',
      'consistent-return': 'error',
      'curly': ['error', 'all'],
    },
  }
];

package.json

{
  "devDependencies": {
    "@aws-sdk/client-lambda": "^3.726.0",
    "@aws-sdk/client-secrets-manager": "^3.726.0",
    "@aws-sdk/client-sfn": "^3.726.0",
    "@babel/core": "^7.26.0",
    "@babel/eslint-parser": "^7.25.9",
    "@babel/preset-env": "^7.26.0",
    "@eslint/js": "^9.17.0",
    "axios": "^1.7.9",
    "eslint": "^9.17.0",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-prettier": "^5.2.1",
    "globals": "^15.14.0",
    "pg": "^8.13.1",
    "prettier": "^3.4.2",
    "serverless": "^3.39.0",
    "serverless-bundle": "^6.3.1",
    "serverless-dotenv-plugin": "^6.0.0",
    "serverless-iam-roles-per-function": "^3.2.0",
    "serverless-offline": "^13.9.0",
    "serverless-offline-lambda": "^1.0.6",
    "serverless-plugin-log-retention": "^2.0.0",
    "serverless-step-functions": "^3.21.2"
  }
}

本文标签: nodejsEslint on a serverless project returns require() of ESModule errorStack Overflow