-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no-undef error on ES6 import #1978
Comments
I'm having the same issue. I've turned on all of the Based on having seen that #1543 wasn't picking up the rest args I was figuring this is probably an issue with escope. escope definitely supports imports eslint's [email protected] uses [email protected] which does include es6-import |
Could be an escope issue, but also could be the rule itself. Need to investigate. |
I'm also seeing this. Source: import Promise from 'bluebird'
import { partial as par, compose, merge, waitForEvent } from 'lodash'
import shortid from 'shortid'
import Log from './log'
import JsonStream from 'json-stream2'
export default function DeviceConnection(socket) {
socket.subscribers = {}
socket.log = Log.child(socket.profile) // <--- ERROR no un-def for `Log`
|
the link sent by @AsaAyers is a good hint, the identifiers of an import are not expected to be on global scope (scopes[0]) https://github.com/estools/escope/blob/master/test/es6-import.coffee#L39 but on a separate one instead https://github.com/estools/escope/blob/master/test/es6-import.coffee#L42 The no-undef rule uses a context.getScope https://github.com/eslint/eslint/blob/master/lib/rules/no-undef.js#L99 that returns only scopes[0] https://github.com/eslint/eslint/blob/master/lib/eslint.js#L953 and the imported variable is not there because it is stored in a different object (with scopes type module). The eslint-babel parser project is having this same bug babel/babel-eslint#15 here is one patch example of a fork that attempts to fix this: BenoitZugmeyer/babel-eslint@f9a84aa |
Not yet helpful, but diving a bit into the import $ from 'jquery';
import BaseView from 'BaseView';
import NotifcationView from 'view/notification'; Here is the logging I added to the currentScopes.forEach(function(scope) {
console.log(scope.type, scope.variables.map(function(x) { return x.name; }), "\n");
}); Here is the result:
So I'm not sure if we're getting what we need from |
Here is a similar testcase to help understand the issue: // install each tip of the branch with:
// npm install jquery/esprima#harmony
// npm install eslint/espree
// npm install estools/escope
// cd node_modules/escope && node_modules/.bin/gulp build && cd ../../
var esprima = require('esprima');
var espree = require('espree');
var escope = require('escope');
var code = 'import v from "mod"';
var esprimaConfig = {
sourceType: 'module'
};
var espreeConfig = {
ecmaFeatures: {
modules: true
}
};
var escopeConfig = {
ecmaVersion: 6,
sourceType: 'module'
};
var ast1 = esprima.parse(code, esprimaConfig);
var ast2 = espree.parse(code, esprimaConfig);
var ast3 = espree.parse(code, espreeConfig);
var scopeManager1 = escope.analyze(ast1, escopeConfig);
var scopeManager2 = escope.analyze(ast2, escopeConfig);
var scopeManager3 = escope.analyze(ast3, escopeConfig);
console.log('esprima harmony:', scopeManager1.scopes[1].variables);
console.log('eslint espree w/ esprima conf', scopeManager2.scopes[1].variables);
console.log('eslint espree:w/ espree conf', scopeManager3.scopes[1].variables); Output:
|
This is an interesting discussion, but it should be taking place in an escope issue, not here. It looks like escope hasn't been updated to respect the latest AST structure for modules. |
is this the estools/escope#33 or a new unfilled one? |
Best to start a new one. |
filed estools/escope#51 |
Thanks! |
@fczuardi |
I don't know if that fix also fixes this one, need to test it, can you please try updating your node_modules/eslint/node_modules/escope to the tip of their master and see if it works please? |
@fczuardi seems like they didn’t release it yet. Anyway there is same issue with fresh |
you don't need to wait for a release, you can always install tip of the master of any npm package with |
@fczuardi it is open soource project, so I can’t ask every contributor to has so difficult install process. Also I prefer to wait rather that create difficult |
@fczuardi but @keithamus said that this fix is works for him. |
Fixed with latest |
eslint still has 2.0.6 https://github.com/eslint/eslint/blob/master/package.json#L42 have you tested before closing the bug? |
|
@fczuardi since it's specified with caret |
PS: I can confirm it's working now! 👍 |
nice \o/ |
This resolved the |
My work-around was to go into node_modules/eslint/ and edit package.json to require escope 2.0.7 then nom install [email protected] from there. This might have to be done in your global packages, too, for me it was |
Upgrading to 2.0.7 broke other things whichis why it was not in the latest release: #2001 |
I too am using the inline global variable whitelist as a temp workaround. Not ideal, but easy to remove once the issue is fixed. |
@emmenko we are waiting for a fix from escope, so you'll need to workaround this for now. When there is an update, it will be posted here. |
@nzakas perfect, many thanks! :) |
Going to see if I can workaround while waiting for escope. |
Fix: module import specifiers should be defined (refs #1978)
Maybe this is in line with this issue, but using 0.17, given this code (with es6 env and modules turned on): import auth from 'basic-auth'
var foo = {}
var creds = auth(foo)
foo.creds = {
username: creds.name,
password: creds.pass
} Gives this error:
Another one is this code: import auth from 'basic-auth' Gives this error:
|
@wavded that's a completely separate issue, can you open a separate issue? |
Sure thing. #2071 |
Maybe I can help? 1.8 release and still not fix this issue (but we had some fix before) |
The "fix" from before resulted in regressions in other areas, which is why it was removed. The only real solution here is to get to the point where we can upgrade escope. To do that, the parser needs updating. |
Fixed by #2235 |
Still having the same error 'Illegal import declaration (undefined)' in atom.io: import _ from 'underscore';
import Promise from 'bluebird'; |
@FrenchBen, what is your |
@IanVS eslintrc is as follow: root: true
ecmaFeatures:
modules: true
jsx: true
arrowFunctions: true
blockBindings: true
env:
node: true
es6: true
browser: true
extends:
"eslint:recommended" then a bunch of rules... mostly taken from the eslintrc found in this repo |
Do you get the same error if you run eslint directly, outside of atom? |
It deosn't seem to complain about it - Guess the plugin/package for atom is to blame :[ ? |
I'd suggest opening an issue there, if one does not already exist. |
will do - thanks for the quick response. |
As I understand ESLint doesn’t understand that
import
create variable.So I get a
'Warning' is not defined
error on line 2 of this code:I uses eslint 0.16.1 and my
.eslintrc
is:/cc @nzakas
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: