question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Including external js with allowJs for Angular 5

See original GitHub issue

Versions

Angular CLI: 1.6.1

Angular CLI: 1.6.1 Node: 9.3.0 OS: win32 x64 Angular: 5.2.0 … animations, common, compiler, compiler-cli, core, forms … http, language-service, platform-browser … platform-browser-dynamic, router

@angular/cli: 1.6.1 @angular-devkit/build-optimizer: 0.0.38 @angular-devkit/core: 0.0.25 @angular-devkit/schematics: 0.0.48 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.9.1 @schematics/angular: 0.1.13 @schematics/schematics: 0.0.13 typescript: 2.4.2 webpack: 3.10.0

Repro steps

  • Step 1 ng new AppName

  • Step 2 npm jsplumb install --save

  • Step 3 Add import to angular-cli “styles”: [ “…/node_modules/jsplumb/dist/css/jsplumbtoolkit-defaults.css”, “styles.css”
    ],

    and
    
    "scripts": ["../node_modules/jsplumb/dist/js/jsplumb.js"],
    
  • Step 4 Include jsplumb in app.component.ts import { jsPlumb } from ‘…/…/…/node_modules/jsplumb/dist/js/jsplumb.js’;

  • Step 5 ng build or ng serve to compile and/or build application.

Observed behavior

With the first build without any configuration to tsconfig.json I get 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. With “allowJs”:true in the tsconfig.json get the following error

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.

### Desired behavior
<!--
What would like to see implemented?
What is the usecase?
What did you expect to see?
-->
Should build angular application with external js file.

### Mention any other details that might be useful (optional)
tsconfig.json
{
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs":true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

[Stackoverflow ](https://stackoverflow.com/questions/48219888/issue-adding-third-party-external-js-lib-in-angular5)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ameyacommented, Feb 16, 2018

I have tested out the newer version of cli that is 1.6.8 but still, the issue is not resolved. Followed the steps mentioned in this link to upgrade

0reactions
angular-automatic-lock-bot[bot]commented, Sep 9, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue adding third-party (external ) js lib in angular5
I am working on to add jsplumb community js library version with the angular 5 application (Angular CLI: 1.6.1). With the first build...
Read more >
How to Use JavaScript Libraries in Angular Project
To include and use the library, the standard way would be to install the library using npm and then look for its type...
Read more >
How to use external JS files and JavaScript code in Angular 6/7
In this tutorial you can learn how to use external js files and how to use JavaScript code in Angular 6/7.
Read more >
Angular compiler options
A TypeScript configuration can inherit settings from another file using the extends property. The configuration options from the base file are loaded first, ......
Read more >
TSConfig Reference - Docs on every TSConfig option
js and .jsx if allowJs is set to true). Default: [] if files is specified, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found