Skip to content
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

Error with import.meta.url #265

Closed
frogamic opened this issue Aug 7, 2020 · 0 comments · Fixed by #266
Closed

Error with import.meta.url #265

frogamic opened this issue Aug 7, 2020 · 0 comments · Fixed by #266
Labels

Comments

@frogamic
Copy link

frogamic commented Aug 7, 2020

Eslint is throwing the following error on import.meta.url when the eslint-plugin-mocha plugin is loaded:

$ $(npm bin)/eslint minimal.js

Oops! Something went wrong! :(

ESLint: 7.6.0

TypeError: Cannot set property 'meta' of undefined
Occurred while linting /project/minimal.js:2
    at MetaProperty (/project/node_modules/eslint-plugin-mocha/lib/rules/prefer-arrow-callback.js:234:27)
    at /project/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/project/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/project/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/project/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:673:23)
    at (/project/node_modules/eslint/lib/linter/linter.js:949:32
    at Array.forEach (<anonymous>)

I am using nodejs v14.7.0 on MacOS, eslint 7.6 and eslint-plugin-mocha 8.0, I have "type": "module" specified in my package.json

This is my .eslintrc.cjs, removing plugins: ['mocha'] and 'plugin:mocha/recommended' from extends causes eslint to parse the file correctly.

module.exports = {
	env: {
		es2020: true,
		node: true,
	},
	parserOptions: {
		ecmaVersion: 2020,
	},
	plugins: ['mocha'],
	extends: ['airbnb-base', 'plugin:mocha/recommended'],
	rules: {
		'mocha/prefer-arrow-callback': ['error'],
		'mocha/no-setup-in-describe': 'off',
		'import/extensions': ['error', 'always'],
		'implicit-arrow-linebreak': 'off',
		'arrow-parens': ['error', 'as-needed'],
		'no-confusing-arrow': 'off',
		'no-tabs': 'off',
		indent: ['error', 'tab'],
	},
	overrides: [
		{
			files: ['*.test.js'],
			rules: {
				'func-names': 'off',
				'prefer-arrow-callback': 'off',
				'no-unused-expressions': 'off',
			},
		},
	],
};

Minimal javascript file to reproduce the error:

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const pkg = require('./package.json');
console.log(pkg.name);
@lo1tuma lo1tuma added the bug label Aug 8, 2020
lo1tuma added a commit that referenced this issue Aug 25, 2020
Fix prefer-arrow-callback to not fail when using import.meta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants