Closed
Description
I've installed the following within my .travis.yml
:
...
- npm install -g eslint babel-eslint
- npm install -g eslint-plugin-react
...
However, implementing eslint
on my jsx templates, generate the following traceback errors, from my travis ci:
...
$ eslint . --ext=jsx -c test/config/eslint.json
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/general/spinner.jsx
13:16 error Parsing error: Unexpected token <
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/general/submit.jsx
17:16 error Parsing error: Unexpected token <
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/input-data/supply_dataset_file.jsx
86:13 error Parsing error: Unexpected token <
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/input-data/supply_dataset_url.jsx
79:13 error Parsing error: Unexpected token <
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/input-data/supply_predictors.jsx
52:13 error Parsing error: Unexpected token <
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/result/result_display.jsx
23:17 error Parsing error: Unexpected token <
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/session-type/data_append.jsx
13:1 error Parsing error: The keyword 'import' is reserved
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/session-type/data_new.jsx
10:1 error Parsing error: The keyword 'import' is reserved
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/session-type/model_generate.jsx
66:13 error Parsing error: Unexpected token <
/home/travis/build/jeff1evesque/machine-learning/src/jsx/import/session-type/model_predict.jsx
10:1 error Parsing error: The keyword 'import' is reserved
/home/travis/build/jeff1evesque/machine-learning/src/jsx/select_session.jsx
10:1 error Parsing error: The keyword 'import' is reserved
✖ 11 problems (11 errors, 0 warnings)
The command "eslint . --ext=jsx -c test/config/eslint.json" exited with 1.
...
This is strange, because nothing substantial has changed in my jsx templates. And just last week, my eslint
, had no problems linting within my travis ci. Perhaps latest changes within this repo, has broke my linting process?
Note: travis ci build logs can be reviewed, to see when eslint
refused to accept my jsx syntax.
Activity
jeff1evesque commentedon Feb 16, 2016
Even though the
eslint
fails, with the above copied traceback, from my travis ci implementation, doing a manualvagrant up
, on my repository:yields a fully functional project (on the master branch). So, the
eslint
generates the above errors, even though my react jsx templates, are working as I intend.ljharb commentedon Feb 16, 2016
For one, React needs to be in scope for jsx to work, and you aren't requiring React in any of those files.
jeff1evesque commentedon Feb 16, 2016
My react is working fine. I did a fresh build off a
vagrant up
. All my jsx eventually ends up as minified javascript. I'm not usingrequire()
, if that's what you're wondering. I'm using es6'simport
/export
. Nevertheless, I haven't figured out yet, why my travis ci has suddenly broke, with respect toeslint
.jeff1evesque commentedon Feb 16, 2016
The following is my
eslint.json
configuration, used viaeslint
, within.travis.yml
:yannickcr commentedon Feb 16, 2016
Seems your problem come from here.
By doing this you are always installing the latest ESLint release, which can introduce some breaking changes if a new major version is released... and this is what happened a few days ago with the release of ESLint 2.0.0.
Since ESLint 2.0.0 the parser options format changed (migration guide), so with your current configuration the JSX/module support is not enabled.
You should replace
by
Another solution is to use
babel-eslint
instead of the ESLint default parser (you are installing it but it is not used in your.eslintrc
config file), for this add the following line in your.eslintrc
Generally speaking you should at least fix the major versions of your dependencies to avoid future breaking changes, for example:
jeff1evesque commentedon Feb 16, 2016
@yannickcr, works, thank you! I will be implementing your additional suggestion, by installing all my package dependencies, at major versions.
hybrisCole commentedon Apr 11, 2016
Got the same problem and tried this:
Did not want to go with the babel-eslint fix because I'm using react native I think that's an unnecesary extra step to transpile it.
yannickcr commentedon Apr 12, 2016
babel-eslint
does not transpile your code, it just allow you to use the Babel parser (Babylon) instead of ESLint default one (Espree) to parse your code.But can you post your full .eslintrc config file, the code that trigger the error and the eslint/eslint-plugin-react versions ? Thanks.
hybrisCole commentedon Apr 12, 2016
Yup that's true hehe, sorry about the misconception.
Here's my .eslint:
Here's my package.json:
So I'm basically learning React Native and wanted it to add eslint to my project, the code that fails is the tutorial code from React Native:
I added
"sourceType": "module",
in the .eslintrc and import keyword error stopped happening,Regards,
landed1 commentedon May 11, 2016
I am using webpack like this :
{ test: /\.jsx?$/, exclude: /(node_modules|bower_components)/, include:"./src/", loader: 'babel', query: { presets: ['react', 'es2015', 'stage-0'], plugins: [ 'transform-runtime', 'transform-decorators-legacy', 'transform-object-rest-spread' ], cacheDirectory: true } }
Do we need 2 files ?
.eslint
.eslintrc
an where do both live ? I am hoping for project root.I am almost there with linting JSX in .js files in my react project its just failing to spot the
Clarity would be most welcome TY
20 remaining items
Update eslint settings to support the new options format.
kselax commentedon Jun 21, 2019
I added to the .eslintrc and it doesn't help
{ "parserOptions": { "ecmaVersion": 7, "sourceType": "module", "ecmaFeatures": { "jsx": true, } }, "rules": { "semi": ["error", "always"], "quotes": ["error", "double"], } }
Configure webpack (copied from source), babel. Because webpack uses e…
jmalik001 commentedon Nov 8, 2019
"parser": "babel-eslint" in .eslintrc.json solved my problem
ljharb commentedon Nov 8, 2019
eslint has fixed its issue anyways.
kmmbvnr commentedon Dec 13, 2019
Fixed by setting ecmaVersion and sourceType
ajzawawi commentedon Jan 7, 2020
sourceType: "module" works. If you're using VSCode or Atom, restarting the editor after making the change helps. It should pick it up after.
cagross commentedon Feb 10, 2020
ljharb commentedon Feb 11, 2020
cagross commentedon Feb 14, 2020
hammerhai commentedon Feb 29, 2020
Did anyone try this with their
.eslintrc.js
?I did that and it works perfectly fine for using something like
import * as firebase from 'firebase/app'
amir-mustafa commentedon Oct 20, 2021