简体   繁体   English

奇怪的 eslint 错误“解析错误:意外令牌 =(致命)”

[英]Weird eslint error "Parsing error: Unexpected token = (Fatal)"

I'm trying to setup auth0 on a react app and this error keeps popping up on my auth0= new auth0.WebAuth({ initializtion, I'm trying to disable eslint with /* eslint-disable */ but it's not working.我正在尝试在 React 应用程序上设置 auth0 并且此错误不断出现在我的auth0= new auth0.WebAuth({初始化,我正在尝试使用/* eslint-disable */禁用 eslint,但它不起作用。

This is my Auth.js file:这是我的 Auth.js 文件:

// imports EventEmitter
import { EventEmitter } from 'events';
// imports the Auth0 JS library
import auth0 from 'auth0-js';
// imports Auth0 credentials from the auth0-variables.js file
import { AUTH_CONFIG } from './auth0-variables';
// imports the history module, which will be created later
import history from '../history';

export default class Auth extends EventEmitter {
    // An instance of Auth0 is instantiated with Auth0 credentials gotten from the auth0-variables.js file


    auth0 = new auth0.WebAuth({ //this is where I'm getting the error

    domain: AUTH_CONFIG.domain,
    clientID: AUTH_CONFIG.clientId,
    redirectUri: AUTH_CONFIG.callbackUrl,
    audience: `https://${AUTH_CONFIG.domain}/userinfo`,

    // Telling Auth0 what to return after a successful authentication, in this case, the token and the id_token
    responseType: 'token id_token',

    // To retrieve a user's profile after authentication, we need to add openid profile to the the scope.
    scope: 'openid profile'
  });

This is my .eslint:这是我的 .eslint:

{
  "extends": [
    "eslint:recommended",
    "plugin:import/errors",
    "plugin:import/warnings"
  ],
  "plugins": [
    "react"
  ],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
       "jsx": true,
       "modules": true,
       "experimentalObjectRestSpread": true
    }
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true,
    "jquery": true,
    "mocha": true
  },
  "rules": {
    "no-unexpected-multiline": "warn",
    "comma-dangle": 0,
    "quotes": 0,
    "no-console": 1,
    "no-debugger": 1,
    "no-var": 1,
    "semi": [1, "always"],
    "no-trailing-spaces": 0,
    "eol-last": 0,
    "no-unused-vars": 0,
    "no-underscore-dangle": 0,
    "no-alert": 0,
    "no-lone-blocks": 0,
    "jsx-quotes": 1,
    "react/display-name": [ 1, {"ignoreTranspilerName": false }],
    "react/forbid-prop-types": [1, {"forbid": ["any"]}],
    "react/jsx-boolean-value": 1,
    "react/jsx-closing-bracket-location": 0,
    "react/jsx-curly-spacing": 1,
    "react/jsx-indent-props": 0,
    "react/jsx-key": 1,
    "react/jsx-max-props-per-line": 0,
    "react/jsx-no-bind": 1,
    "react/jsx-no-duplicate-props": 1,
    "react/jsx-no-literals": 0,
    "react/jsx-no-undef": 1,
    "react/jsx-pascal-case": 1,
    "react/jsx-sort-prop-types": 0,
    "react/jsx-sort-props": 0,
    "react/jsx-uses-react": 1,
    "react/jsx-uses-vars": 1,
    "react/no-danger": 1,
    "react/no-did-mount-set-state": 1,
    "react/no-did-update-set-state": 1,
    "react/no-direct-mutation-state": 1,
    "react/no-multi-comp": 1,
    "react/no-set-state": 0,
    "react/no-unknown-property": 1,
    "react/prefer-es6-class": 1,
    "react/prop-types": 1,
    "react/react-in-jsx-scope": 1,
    "react/require-extension": 1,
    "react/self-closing-comp": 1,
    "react/sort-comp": 1,
    "react/wrap-multilines": 1
  },
}

and this is my package.json:这是我的 package.json:

{
  "name": "TurboWeb",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "prestart": "babel-node tools/startMessage.js",
    "start": "npm-run-all --parallel open:src lint:watch test:watch",
    "open:src": "babel-node tools/srcServer.js",
    "lint": "node_modules/.bin/esw webpack.config.* src tools",
    "lint:watch": "npm run lint -- --watch",
    "test": "mocha --reporter spec tools/testSetup.js \"src/**/*.test.js\"",
    "test:watch": "npm run test -- --watch"
  },
  "author": "Cory House",
  "license": "MIT",
  "dependencies": {
    "auth0-js": "^9.2.2",
    "babel-polyfill": "6.8.0",
    "body-parser": "^1.18.2",
    "bootstrap": "4.0.0-beta.2",
    "events": "^2.0.0",
    "history": "^4.7.2",
    "jquery": "2.2.3",
    "popper.js": "^1.12.9",
    "prop-types": "^15.6.0",
    "pusher": "^1.5.1",
    "react": "15.6.2",
    "react-dom": "15.6.2",
    "react-redux": "4.4.5",
    "react-router": "3.2.0",
    "react-router-redux": "4.0.4",
    "redux": "3.5.2",
    "redux-thunk": "2.0.1",
    "semantic-ui-css": "^2.2.12",
    "semantic-ui-react": "^0.74.2",
    "toastr": "2.1.2"
  },
  "devDependencies": {
    "babel-cli": "6.8.0",
    "babel-core": "6.8.0",
    "babel-loader": "7.1.2",
    "babel-plugin-react-display-name": "2.0.0",
    "babel-preset-es2015": "6.6.0",
    "babel-preset-react": "6.5.0",
    "babel-preset-react-hmre": "1.1.1",
    "babel-register": "6.8.0",
    "cheerio": "0.22.0",
    "colors": "1.1.2",
    "compression": "1.6.1",
    "cross-env": "1.0.7",
    "css-loader": "0.23.1",
    "enzyme": "^3.0.0",
    "enzyme-adapter-react-15": "^1.0.5",
    "eslint": "2.10.1",
    "eslint-plugin-import": "1.6.1",
    "eslint-plugin-react": "5.0.1",
    "eslint-watch": "2.1.11",
    "eventsource-polyfill": "0.9.6",
    "expect": "1.19.0",
    "express": "4.13.4",
    "extract-loader": "^1.0.1",
    "extract-text-webpack-plugin": "3.0.2",
    "file-loader": "^0.8.5",
    "html-loader": "^0.5.1",
    "jsdom": "8.5.0",
    "mocha": "2.4.5",
    "nock": "8.0.0",
    "npm-run-all": "1.8.0",
    "open": "0.0.5",
    "react-addons-test-utils": "15.0.2",
    "react-test-renderer": "^15.5.0",
    "redux-immutable-state-invariant": "1.2.3",
    "redux-mock-store": "1.0.2",
    "rimraf": "2.5.2",
    "style-loader": "0.13.1",
    "url-loader": "^0.5.7",
    "webpack": "^3.10.0",
    "webpack-dev-middleware": "2.0.3",
    "webpack-hot-middleware": "2.10.0"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/coryhouse/pluralsight-redux-starter"
  }
}

and my webpack.config just in case:和我的 webpack.config 以防万一:

import webpack from 'webpack';
import path from 'path';

export default {
    devtool: 'cheap-module-eval-source-map',
    // noInfo: false,
    entry: [
        'eventsource-polyfill', // necessary for hot reloading with IE
        'webpack-hot-middleware/client?reload=true', //note that it reloads the page if hot module reloading fails.
        './src/index'
    ],
    target: 'web',
    output: {
        path: __dirname + '/dist', // Note: Physical files are only output by the production build task `npm run build`.
        publicPath: '/',
        filename: 'bundle.js'
    },
    devServer: {
        inline: false,
        contentBase: './src'
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(), new webpack.NoEmitOnErrorsPlugin(),
        new webpack.ProvidePlugin({ $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        Popper: ['popper.js', 'default'],
        // In case you imported plugins individually, you must also require them here:
        Util: "exports-loader?Util!bootstrap/js/dist/util",
        Dropdown: "exports-loader?Dropdown!bootstrap/js/dist/dropdown"})
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                include: path.join(__dirname, 'src'),
                loaders: 'babel-loader'
            }, {
                test: /(\.css)$/,
                loaders: ['style-loader', 'css-loader']
            }, {
                test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
                loader: 'file-loader'
            }, {
                test: /\.(woff|woff2)$/,
                loader: 'url-loader'
            }, {
                test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
                loader: 'url-loader'
            }, {
                test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
                loader: 'url-loader'
            }, {
                test: /\.(png|jp(e*)g|svg)$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 8000, // Convert images < 8kb to base64 strings
                            name: 'images/[hash]-[name].[ext]'
                        }
                    }
                ]
            }
        ]
    }
};

Class instance properties ( auth = new auth0.WebAuth(/*...*/); inside a class body) are still experimental.类实例属性( auth = new auth0.WebAuth(/*...*/);在类主体内)仍然是实验性的。 You can follow development of the proposal if you're interested - it's at stage 3 of the tc39 proposal process as of this writing.如果您有兴趣,可以关注提案的发展——在撰写本文时,它处于tc39 提案流程的第 3 阶段。

If you want to use class properties today (I see you're using React, and they're pretty common in React code), and assuming you already have Babel set up, ESLint can parse them and other experimental features with the help of babel-eslint .如果你今天想使用类属性(我看到你在使用 React,它们在 React 代码中很常见),并且假设你已经设置了 Babel,ESLint 可以在babel的帮助下解析它们和其他实验性功能-eslint There are more complete instructions on the readme, but you'll want to npm install --save-dev babel-eslint and add "parser": "babel-eslint" to your .eslintrc.json .自述文件中有更完整的说明,但您需要npm install --save-dev babel-eslint并将"parser": "babel-eslint"到您的.eslintrc.json

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM