Closed JoshuaKGoldberg closed 1 year ago
Do you have any thoughts about how to implement it? PR welcome for clearer error messages!
Cannot use import statement outside a module
this errorAh, #461 is enough for me. Thanks!
In case it's useful, I looked at changing the parseForESLint
function's new SyntaxError
to have a more descriptive error message:
throw Object.assign(
new SyntaxError(`Could not parse ${filePath}: ${error.message}`),
{
// ...
},
...but quite a few of the existing test snapshots got a bit uglier:
Could not parse __placeholder__.mdx: Could not parse import/exports with acorn: SyntaxError: Identifier 'A' has already been declared"`,
(note that parser.test.ts
needed to change the parser.parser
to take in filePath: fileName
)
Cheers!
Initial checklist
Problem
I'm trying to setup linting for
.md
and.mdx
files in a repo that already has a bunch of ESLint overrides, such as for TypeScript code. I added a.remarkrc.js
file and used modules in it, causing this error when running ESLint:With ESLint's
--debug
:The user solution on my end is to correct the usage of ES module imports. But that was not easy to get through - I had to put a
console.log({ error })
innode_modules/eslint-mdx/lib/parser.js
to figure out where it was coming from.Solution
When there's an error trying to load the remark config, can we explicitly say it's coming from the source file?
Alternatives
I also filed https://github.com/eslint/eslint/issues/16565 around improving the experience around debugging parsing issues. That likely won't help with this specific issue though.
There's probably a better error message to print than what I suggested, but I can't think of one...