Summary
CodeMirror.ts is being bundled by rollup and built by yarn watch.
The yarn watch build rebuilds TypeScript files when changed and is much faster than the rollup build. Only the output of the rollup build is being used. Even so, the yarn watch build is useful for type checking.
Unfortunately, however, while the following import works with yarn watch, it does not work with rollup if EditorType.js exists:
import { SelectionFormatting } from './EditorType';
yarn watch creates EditorType.js if it doesn't exist.
With this, rollup tries to import SelectionFormatting from EditorType.js (generated by yarn watch). The yarn watch build of CodeMirror.ts, however, imports SelectionFormatting from EditorType.ts.
EditorType.js lacks type information and exports SelectionFormatting as a CommonJS module (not recongnized by rollup).
What (somewhat) works
The following import does work with rollup
12 // We need to specify the file extension (.ts) here.
13 // If we don't, rollup tries to import from the .js file generated
14 // by `yarn watch`, which fails.
15 import { SelectionFormatting } from './EditorType.ts';
Unfortunately, this generates errors when built with yarn watch:
components/NoteEditor/CodeMirror.ts:15:37 - error TS2691: An import
path cannot end with a '.ts' extension. Consider importing './EditorType'
instead.
15 import { SelectionFormatting } from './EditorType.ts';
~~~~~~~~~~~~~~~~~
These errors are also generated by yarn install, but not yarn build.
Because everything else compiles successfully, the app can be deployed. The code also passes the pre-commit tests (I don't know why).
Options
- Ignore the build errors — most things still work
- Exclude
CodeMirror.tsfrom the list of files built byyarn watch, but do include it when bundling with rollup. (This might be tricky —rollupreads the sametsconfig.jsonfiles used byyarn watch/yarn install). - Delete
EditorType.jswhen bundling (may cause issues ifyarn watchnotices thatEditorType.tsneeds to be rebuilt while rollup is building).- Rollup will
importfrom.tsfiles, just not if a.jsfile is present.
- Rollup will
I think I prefer the second option. Has anyone else encountered similar issues in the past/have suggestions on how to fix this?