Currently, I am integrating the community js library version of jsplumb with my Angular 5 application (Angular CLI: 1.6.1).
Upon my initial build without any modifications to tsconfig.json, I encountered the following error:
ERROR in src/app/jsplumb/jsplumb.component.ts(4,25): error TS6143: Module '../../../node_modules/jsplumb/dist/js/jsplumb.js' was resolved to 'D:/myproj/angular5/myapp/node_modules/jsplumb/dist/js/jsplumb.js', but '--allowJs' is not set.
When adding "allowJs": true to the tsconfig.json file, a new error occurred:
ERROR in error TS5055: Cannot write file 'D:/myproj/angular5/myapp/node_modules/jsplumb/dist/js/jsplumb.js' because it would overwrite input file.
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
In accordance with the tsconfig FAQ,
I received the error TS5055: Cannot write file 'xxx.js' because it would overwrite input file.
This issue can be resolved by setting an outDir ("outDir": "./dist/out-tsc") which is already configured in my tsconfig file.
If we set noEmit to true, the application builds successfully but does not include any external js files resulting in a blank white screen.
If anyone has experience dealing with similar errors while integrating external js with Angular CLI, please share your solutions.
By simply modifying a ts file without making additional changes to tsconfig.json, the application compiles successfully for development purposes. However, this method is not suitable for creating a deployable binary using ng build.
Update Workaround: Until a fix is available in CLI, during development (ng serve), remove allowJs from tsconfig.json. When encountering an error related to allowJs, modify a ts file to trigger recompilation, ensuring successful compilation. For production or distribution, add back the allowJs to tsconfig.json and run the application with ng build --prod --watch=auto
. If an error regarding overriding the JS file in node_module occurs, simply modify a ts file to trigger a successful rebuild despite having --watch=auto enabled in the command.