简体   繁体   English

将 eslint 配置从 json 转换为 JavaScript 会在导出配置时引发错误

[英]Converting eslint config from json to JavaScript throws error when exporting config

I am trying to convert my eslint config from json to JavaScript.我正在尝试将我的 eslint 配置从 json 转换为 JavaScript。

After exporting a config object from .eslintrc.js like it sys in the docs :从 .eslintrc.js 中导出配置对象后,如文档中的sys :

JavaScript - use .eslintrc.js and export an object containing your configuration. JavaScript - 使用 .eslintrc.js 并导出包含您的配置的对象。

I get the error:我收到错误:

(function (exports, require, module, __filename, __dirname) { export default {
                                                              ^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:83:7)

This is the first couple of lines of my config:这是我的配置的前几行:

export default {
    env: {
        browser: true,

How can I fix the error?我该如何修复错误?

Update更新

I have named the object and exported the const but get this error:我已经命名了对象并导出了常量,但出现了这个错误:

const config = {
    env: {
export default config;
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:83:7)

you should use module.exports like this:你应该像这样使用 module.exports:

module.exports = {
  putYour: "config here"
};

thats all that you need这就是你所需要的

This is what I have in my .eslintrc.js :这是我在 .eslintrc.js 中的内容:

module.exports = {
    env: {
        browser: true,
...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Eslint 8.0.1 - 在配置中实现 jest 会引发错误 - Eslint 8.0.1 - implementing jest into config throws an error 来自codacy的Eslint配置文件 - Eslint config file from codacy WebStorm eslint-config-standard错误 - WebStorm eslint-config-standard error ESLint 错误 - ESLint 找不到配置“react-app” - ESLint error - ESLint couldn't find the config "react-app" 如何从eslint-config-airbnb有选择地启用eslint规则 - How to selectively enable eslint rules from eslint-config-airbnb ESLINT 生成 JavaScript 配置文件时出错。 怎么修? - ESLINT An error occurred while generating your JavaScript config file. How to fix? 启用全局 ESlint 配置 - Enable global ESlint config 使用 nodemon 重新部署我的 React 应用程序时出错,它一直在说“插件“反应”在“package.json » eslint-config-react”-app » 之间发生冲突 - Error when redeploying my react app with nodemon it keeps sayings "Plugin "react" was conflicted between "package.json » eslint-config-react"-app » 尝试创建提交时出现错误“找不到模块'eslint-config-strict / es5'” - Error “Cannot find module 'eslint-config-strict/es5'” when I try to create a commit eslint 无法加载要扩展的配置“react-app”。 在项目中进行更改时 - eslint Failed to load config "react-app" to extend from. when making changes in project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM