Babel Javascript错误-找到多个配置文件



结构

这是我的项目结构:

/app (The main code of my React app)
/assets (assets)
/core (js code)
/node_modules
/functions (Google Cloud Functions (Serverless))
/src
/node_modules
/utils
/lib
/services
.babelrc.js
.eslintrc.js
package.json
.babelrc.js
.eslintrc.js
.eslintignore
Main.js
package.json

问题

我正在尝试在两个文件夹中配置babel和esint:

  1. 在我项目的根目录中
  2. 在我的函数文件夹中,哪些代码将被部署到Firebase

但是。。。我得到错误:

分析错误:找到多个配置文件。请删除一个:-.babelrc.js

如何解决它?

配置

这是我的函数文件夹的package.json配置:

{
"name": "functions",
"description": "Cloud Functions",
"main": "src/index.js",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"dependencies": {
"@google-cloud/vision": "^2.4.0",
"@googlemaps/google-maps-services-js": "^3.3.3",
"axios": "^0.21.4",
"camelcase": "^6.2.1",
"expo-server-sdk": "^3.6.0",
"firebase-admin": "^9.12.0",
"firebase-functions": "^3.16.0",
"glob": "^7.2.0",
"image-size": "^0.9.7",
"moment": "^2.29.1",
"qs": "^6.10.1",
"sharp": "^0.27.2",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/eslint-parser": "^7.16.3",
"@babel/preset-env": "^7.16.4",
"eslint": "^8.3.0",
"eslint-config-airbnb": "^19.0.2",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^4.3.1",
"firebase-functions-test": "^0.2.0"
},
"private": true
}

这是我的函数文件夹的.babelrc.js配置:

module.exports = function (api) {
api.cache(true);
return {
presets: [
[
"@babel/preset-env",
{
targets: {
node: "current",
},
},
],
],
};
};

最后,这是我的函数文件夹的.eslintrc.js配置:

module.exports = {
plugins: [
"import",
"prettier",
"promise",
],
parser: "@babel/eslint-parser",
parserOptions: {
sourceType: "module",
},
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"airbnb",
"prettier",
"google",
"plugin:import/recommended",
],
rules: ...,
root: true,
};

根据错误,您有babel的多个配置,如放在Cloud Function中的文件(如package.json.babelrc.js(中所述。您可以安全地删除/function目录中的.babelrc.js,然后重新部署您的功能。

别担心。您将添加到您的项目中:

yarn add --save-dev eslint-plugin-import eslint-import-resolver-babel-module

在.eslintrc文件中,将此解析程序传递给eslint插件导入:

{
"extends": "react-app",
"rules": {
"comma-dangle": 0
},
"settings": {
"import/resolver": {
"babel-module": {
allowExistingDirectories: true
}
}
}
}

相关内容

  • 没有找到相关文章

最新更新