npm测试在“ ncu -u”之后返回“ SyntaxError:无法在模块外部使用导入语句”

时间:2020-10-15 17:46:23

标签: node.js mocha nyc

节点版本14.13.1。这是我的tsconfig.json,我已经有了"type": "module",因为我发现了一些答案:

{
  "compilerOptions": {
    "declaration": true,
    "importHelpers": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "lib",
    "target": "es2017",
    "rootDir": "src",
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "types": [
      "node"
    ]
  },
  "include": [
    "src/**/*.ts"
  ]
}

这是我升级后的packages.json

{
  "name": "oma",
  "type": "module",
  "description": "description",
  "version": "0.0.1",
  "author": "email",
  "private": true,
  "bin": {
    "oma": "./bin/run"
  },
  "scripts": {
    "postpack": "rimraf oclif.manifest.json",
    "lint": "eslint . --ext .ts",
    "posttest": "npm run lint",
    "prepack": "npm run clean && tsc -b && oclif-dev manifest",
    "test": "nyc --extension .ts mocha test/**/*.ts",
    "test-ci": "nyc --extension .ts mocha test/**/*.ts --reporter mocha-junit-reporter --reporter-options mochaFile=./bin/test-results.xml",
    "version": "oclif-dev readme && git add README.md",
    "clean": "npx rimraf ./lib"
  },
  "dependencies": {
    "@azure/ms-rest-js": "^2.1.0",
    "@oclif/command": "^1",
    "@oclif/config": "1.17.0",
    "@oclif/plugin-autocomplete": "^0.2.0",
    "@oclif/plugin-help": "^3",
    "@oclif/plugin-not-found": "^1.2.4",
    "ajv": "^6.12.6",
    "archiver": "^5.0.2",
    "axios": "^0.20.0",
    "azure-devops-node-api": "^10.1.1",
    "azure-pipelines-task-lib": "^2.11.3",
    "azure-storage": "^2.10.3",
    "bl": "^4.0.3",
    "diff": "^4.0.2",
    "dotenv": "^8.2.0",
    "googleapis": "61.0.0",
    "ms-rest": "^2.5.4",
    "showdown": "^1.9.1",
    "simple-git": "2.21.0",
    "test-console": "^1.1.0",
    "tslib": "^2"
  },
  "devDependencies": {
    "@oclif/dev-cli": "^1",
    "@oclif/test": "^1",
    "@types/archiver": "^3.1.1",
    "@types/assert": "^1.5.2",
    "@types/chai": "^4.2.13",
    "@types/diff": "^4.0.2",
    "@types/mocha": "^8.0.3",
    "@types/nock": "^11.1.0",
    "@types/node": "^14",
    "@types/request": "^2.48.5",
    "@types/showdown": "^1.9.3",
    "@types/typescript": "^2.0.0",
    "@typescript-eslint/eslint-plugin": "^4.4.1",
    "@typescript-eslint/parser": "^4.4.1",
    "assert": "^2.0.0",
    "chai": "^4",
    "eslint": "^7.11.0",
    "eslint-config-oclif": "^3.1",
    "eslint-config-oclif-typescript": "^0.2",
    "globby": "^11",
    "lodash": "^4.17.20",
    "mocha": "^8.1.3",
    "mocha-junit-reporter": "^2.0.0",
    "mocha-typescript": "^1.1.17",
    "moment": "2.29.1",
    "nock": "^13.0.4",
    "nyc": "^15",
    "request": "^2.88.2",
    "rimraf": "^3.0.2",
    "ts-node": "^9",
    "typescript": "^4.0.3"
  },
  "resolutions": {
    "lodash": "4.17.19"
  },
  "engines": {
    "node": ">=8.0.0"
  },
  "files": [
    "/bin",
    "/lib",
    "/npm-shrinkwrap.json",
    "/oclif.manifest.json"
  ],
  "keywords": [
    "oclif"
  ],
  "license": "MIT",
  "main": "lib/index.js",
  "oclif": {
    "commands": "./lib/commands",
    "hooks": {
      "init": "/src/InitHook"
    },
    "bin": "oma",
    "topics": {
      "app-center": {
        "description": "description"
      }
    },
    "plugins": [
      "@oclif/plugin-help",
      "@oclif/plugin-autocomplete",
      "@oclif/plugin-not-found"
    ]
  },
  "types": "lib/index.d.ts"
}

这是升级之前:

{
  "name": "oma",
  "description": "description",
  "version": "0.0.1",
  "author": "email",
  "private": true,
  "bin": {
    "oma": "./bin/run"
  },
  "scripts": {
    "postpack": "rimraf oclif.manifest.json",
    "lint": "eslint . --ext .ts",
    "posttest": "npm run lint",
    "prepack": "npm run clean && tsc -b && oclif-dev manifest",
    "test": "nyc --extension .ts mocha test/**/*.ts",
    "test-ci": "nyc --extension .ts mocha test/**/*.ts --reporter mocha-junit-reporter --reporter-options mochaFile=./bin/test-results.xml",
    "version": "oclif-dev readme && git add README.md",
    "clean": "npx rimraf ./lib"
  },
  "dependencies": {
    "@azure/ms-rest-js": "^2.0.5",
    "@oclif/command": "^1",
    "@oclif/config": "1.15.1",
    "@oclif/plugin-autocomplete": "^0.1.5",
    "@oclif/plugin-help": "^2",
    "@oclif/plugin-not-found": "^1.2.3",
    "ajv": "^6.12.5",
    "archiver": "^3.1.1",
    "axios": "^0.19.2",
    "azure-devops-node-api": "^10.1.0",
    "azure-pipelines-task-lib": "^2.9.3",
    "azure-storage": "^2.10.3",
    "bl": "^4.0.3",
    "diff": "^4.0.2",
    "dotenv": "^8.2.0",
    "googleapis": "60.0.1",
    "ms-rest": "^2.5.4",
    "showdown": "^1.9.1",
    "simple-git": "2.5.0",
    "test-console": "^1.1.0",
    "tslib": "^1"
  },
  "devDependencies": {
    "@oclif/dev-cli": "^1",
    "@oclif/test": "^1",
    "@types/archiver": "^3.1.0",
    "@types/assert": "^1.4.6",
    "@types/chai": "^4.2.11",
    "@types/diff": "^4.0.2",
    "@types/mocha": "^7.0.2",
    "@types/nock": "^11.1.0",
    "@types/node": "^10",
    "@types/request": "^2.48.4",
    "@types/showdown": "^1.9.3",
    "@types/typescript": "^2.0.0",
    "@typescript-eslint/eslint-plugin": "^2.26.0",
    "@typescript-eslint/parser": "^2.26.0",
    "assert": "^2.0.0",
    "chai": "^4",
    "eslint": "^6.8.0",
    "eslint-config-oclif": "^3.1",
    "eslint-config-oclif-typescript": "^0.1",
    "globby": "^10",
    "lodash": "^4.17.19",
    "mocha": "^7.1.1",
    "mocha-junit-reporter": "^2.0.0",
    "mocha-typescript": "^1.1.17",
    "moment": "2.26.0",
    "nock": "^12.0.3",
    "nyc": "^14",
    "request": "^2.88.2",
    "rimraf": "^3.0.2",
    "ts-node": "^8",
    "typescript": "^3.8.3"
  },
  "resolutions": {
    "lodash": "4.17.19"
  },
  "engines": {
    "node": ">=8.0.0"
  },
  "files": [
    "/bin",
    "/lib",
    "/npm-shrinkwrap.json",
    "/oclif.manifest.json"
  ],
  "keywords": [
    "oclif"
  ],
  "license": "MIT",
  "main": "lib/index.js",
  "oclif": {
    "commands": "./lib/commands",
    "hooks": {
      "init": "/src/InitHook"
    },
    "bin": "oma",
    "topics": {
      "app-center": {
        "description": "description"
      }
    },
    "plugins": [
      "@oclif/plugin-help",
      "@oclif/plugin-autocomplete",
      "@oclif/plugin-not-found"
    ]
  },
  "types": "lib/index.d.ts"
}

很抱歉,冗长的帖子。唯一的嫌疑人是摩卡咖啡7-> 8,但我搜索并没有看到如何导致此错误

0 个答案:

没有答案