Parse errors in imported module 'http-status-codes': parser.parse is not a function (undefined:undefined)
Closed this issue · 6 comments
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
What version of ESLint are you using?
8.53.0
What version of eslint-plugin-astro
are you using?
0.29.1
What did you do?
Configuration
{
"extends": [
"standard-with-typescript",
"plugin:import/recommended",
"plugin:import/typescript"
],
"plugins": ["astro"],
"overrides": [
{
"files": ["*.astro"],
"parser": "astro-eslint-parser",
"parserOptions": {
"parser": "@typescript-eslint/parser",
"extraFileExtensions": [".astro"]
}
}
]
}
---
import { StatusCodes } from 'http-status-codes';
console.log(StatusCodes.MOVED_TEMPORARILY);
---
<div></div>
What did you expect to happen?
There should be no linter errors about the import of the module. When I import this module inside a .ts
file, there’s no error.
What actually happened?
eslint src/pages/index.astro
Error while parsing node_modules/http-status-codes/build/es/index.js
Line 3, column 52: Unable to assign attributes when using <> Fragment shorthand syntax! [1002]
`parseForESLint` from parser `node_modules/astro-eslint-parser/lib/index.js` is invalid and will just be ignored
/home/arty/Entwicklung/galaniprojects/typescript-eslint-astro-fragment/src/pages/index.astro
0:1 error This rule requires the `strictNullChecks` compiler option to be turned on to function correctly @typescript-eslint/prefer-nullish-coalescing
0:1 error This rule requires the `strictNullChecks` compiler option to be turned on to function correctly @typescript-eslint/strict-boolean-expressions
2:29 error Parse errors in imported module 'http-status-codes': parser.parse is not a function (undefined:undefined) import/namespace
2:48 error Extra semicolon @typescript-eslint/semi
✖ 4 problems (4 errors, 0 warnings)
1 error and 0 warnings potentially fixable with the `--fix` option.
Link to Minimal Reproducible Example
https://github.com/arty-name/typescript-eslint-astro-fragment
The branch is called import
Additional comments
The parser complains about line 3 in the file node_modules/http-status-codes/build/es/index.js, here’s what this line looks like
for (var s, i = 1, n = arguments.length; i < n; i++) {
The "erroneous" column 53 is the "less" character in the comparison i < n
I tried with your repository but can't reproduce the problem.
However, I suspect that you may need to add the following to your configuration:
settings: {
// ...
'import/parsers': {
'astro-eslint-parser': ['.astro'],
'espree': ['.js'],
}
https://github.com/import-js/eslint-plugin-import#importparsers
If you would like us to do additional research, please first provide a reproducible repository.
Thank you for testing! Just making sure: have you tried it with the import
branch?
I have just reproduced it on another computer with these commands:
git clone git@github.com:arty-name/typescript-eslint-astro-fragment.git
cd typescript-eslint-astro-fragment/
git checkout import
npm install
npm run start
The issue persists when providing the settings
"settings": {
"import/parsers": { "astro-eslint-parser": [".astro"] }
},
Oh, my bad. I was using the main
branch. I can reproduce it using the import
branch.
By adding the configuration in the import
branch, it seems to work fine.
"settings": {
"import/parsers": {
"astro-eslint-parser": [".astro"],
"espree": [".js"]
}
}
Indeed, the presence of "espree": [".js"]
was crucial, thank you!