You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
even though the file is using .mjs extension. After some digging I found the problem is this plugin's config which enforces languageOptions.sourceType: 'commonjs' for all files. ESLint 9 already sets the sourceType correctly based on type field in package.json and file extensions (.js/.cjs/.mjs), so there's no need for this plugin to configure this.
What do you think is the correct solution?
Don't set sourceType in language options and let ESLint handle this instead... see this playground where I removed the field from the config object and then it works fine.
importnodefrom'eslint-plugin-n'constnodeRecommended=node.configs['flat/mixed-esm-and-cjs']nodeRecommended.forEach(config=>deleteconfig.languageOptions?.sourceType)exportdefault[
...nodeRecommended,// more stuff]
and that works fine for me (.js files based on type field in package.json, and .cjs/.mjs fixed to CommonJS/ESM respectively).
So I'm also for making mixed-esm-and-cjs the actual recommended config.
I'd also drop the languageOptions.sourceType config, however I'm not sure if ESLint 8 also sets that correctly already.
eslint-plugin-n version
17.10.2
What problem do you want to solve?
https://eslint-online-playground.netlify.app/#eNpVjjsOwjAQRK9ibZMGzKfh13ILlsKy15HBXltxQJGi3J04SUHanfd2pofc6B11KiRPMrwyXMGFFJtW2CxsE4OobK5gA5S941bqyNbVa5KjoZnFBdsm/6kdbxnhhoxM3QQasurjW/FAFpO1vMuPynrV7hrSMQRiQ6Z6Ij9Hd2xOSr9VTfKVI4+lfZERDH3vlArL2lFGuIopKdk8opwQLvIs9wibdfY3sECHkzzs5RGhUAPyAMMPStleUQ==
☝️ gives
even though the file is using
.mjs
extension. After some digging I found the problem is this plugin's config which enforceslanguageOptions.sourceType: 'commonjs'
for all files. ESLint 9 already sets the sourceType correctly based ontype
field inpackage.json
and file extensions (.js
/.cjs
/.mjs
), so there's no need for this plugin to configure this.What do you think is the correct solution?
Don't set
sourceType
in language options and let ESLint handle this instead... see this playground where I removed the field from the config object and then it works fine.https://eslint-online-playground.netlify.app/#eNpdkDFPAzEMhf9K5OWWNm1ZgCLEwo6E2GqGKHFOKYkTXXKoqLr/ziVXCdrV73vPfj5DHvSGTiokTzIcM+zBhRSHImwWdohBdDZ3sALK3nGROrJ1/TXJ0dDC4gVbJz/2jteM8ISMPLvywr2TjiEQGzLiuU0ukfnQWa/KZvgDus9mNuSp0K1besX9qHp6S8XN8S8yx3HQ9PGTqNno1I4zZNXoizggi9sM5LphLpeU/pqj5DFHnnudK4tg6PuVUiVZO8oIe9GUqi096wjhUT7ILcLqWvv3gwrt7uVuK+8QKjUhTzD9AiiihF8=
Participation
Additional comments
Not sure if it's the same for ESLint 8.
The text was updated successfully, but these errors were encountered: