错误 [ERR_MODULE_NOT_FOUND]:找不到从 eslint.config.mjs 导入的包“globals”

问题描述 投票:0回答:1

我正在尝试使用 Linux 运行程序设置 gitlab CI/CD。我遇到了一些问题,首先它找不到 eslint 作为命令,在全局安装它之后,由于某种原因它可以工作,但现在我遇到了找不到全局变量的问题。谁能帮我解决这个问题吗?这是我的

eslint.config.mjs
:

import globals from "globals";
import pluginJs from "@eslint/js";
import stylisticJs from '@stylistic/eslint-plugin-js'


/** @type {import('eslint').Linter.Config[]} */
export default [
  {
    files: ["src/**/*.js"],
    ignores: [
      "src/database/**/*"
    ],
    languageOptions: {
      globals: {
        ...globals.node
      }
    },
    rules: {
      "prefer-const": "warn",
      "no-constant-binary-expression": "error",
      "camelcase": "error",
      "@stylistic/js/indent": ["error", 2],
      "@stylistic/js/object-curly-spacing": ["error", "never"],
      "@stylistic/js/quotes": ["error", "double"],
      "no-console": "off"
    },
    plugins: {'@stylistic/js': stylisticJs}
  },
];

这是我的 gitlab-ci.yml 文件:

image: node:latest

stages:
  - install
  - lint
  - build

variables:
  NODE_ENV: production


install:
  stage: install
  script:
    - cd server
    - npm ci
  artifacts:
    paths:
      - server/node_modules/

eslint:
  stage: lint
  before_script:
    - cd server
    - npm ci
  script:
    - npm i -g eslint
    - npm i -g globals
    - npm run lint
  allow_failure: false
  

build:
  stage: build
  script:
    - cd server
    - npm ci
    - npm run build
  dependencies:
    - install
  artifacts:
    paths:
      - server/dist/

workflow:
  rules:
    - if: $CI_MERGE_REQUEST_ID
      when: always

我现在不知道该怎么办。如果您需要任何日志,请问我。

eslint cicd
1个回答
0
投票

应该预运行推荐

npm install 

© www.soinside.com 2019 - 2024. All rights reserved.