fix: add missing file extension in imports of the npm package #301
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Webpack follows node.js rules for imports:
The ‘type’ of the library is defined as ‘module’ in the package.json file, so this behaviour is applied. So, the imports have been updated to include the .js file extension. An eslint plugin is used to enforce and automatically fix missing file extension in imports.
Previously, as the imports didn't include the file extension in version 0.7.0 of the library, webpack raised errors like in the following:
Notes
webpack details
Extensions in import and TypeScript transpilation
TypeScript has not planned to change the imports declared in the ts files at transpilation time. See microsoft/TypeScript#16577 (comment)
New eslint rule to enforce js extension in imports
See https://github.com/eslint-community/eslint-plugin-n/blob/85b794508a0fb92e021c09e63378314093772640/docs/rules/file-extension-in-import.md
https://github.com/import-js/eslint-plugin-import/blob/v2.23.4/docs/rules/extensions.md was also experimented (see below for more details).
About this problem in
bpmn-visualization
There is no problem in
bpmn-visualization
. We provide a single bundle file which is referenced in the package.json. So, there is no JS files importing other modules.Investigating using the
extensions
rule ineslint-plugin-import
.I have not been able to get it to work. Also,
eslint-plugin-import
does not provide automatic correction for erroneous imports, whereaseslint-plugin-n
does. It's a pain. So, for all these reasons, I've decided to stick witheslint-plugin-n
, at least for now.I have followed
I got errors like these
The problem may be due to an unresolved issue: import-js/eslint-plugin-import#2111
Tasks
No need to add a new dependency withI have not been able to make it work (see above), so keep usingeslint-plugin-n
. Use the rules available in the import plugin https://github.com/import-js/eslint-plugin-import/blob/v2.23.4/docs/rules/extensions.md.eslint-plugin-n
.a TypeScript configuration may also enforce this. See A compiler option to enforce file extensions. microsoft/TypeScript#42813 and moduleResolution bundler https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html#considerations-for-bundling-libraries--> not accurate for our use case