1

I'm installing js-beautify from https://www.npmjs.com/package/js-beautify

via npm install js-beautify --save

Then adding import to my app.component.ts

documentations says to

import jsbeautifier

But it needs quotes, so I'm using

import 'jsbeautifier'

but after that when I'm trying to use it I'm receiving error:

Failed to compile.

./src/app/app.component.ts
Module not found: Error: Can't resolve 'jsbeautifier' in '/home/oscar/IdeaProjects/lodashteatcherv4/src/frontend/src/app'
 @ ./src/app/app.component.ts 14:0-22
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

I tried also this import

import '../../node_modules/js-beautify/js/lib/beautify.js'

I'm using angular cli 2/4

1

1 Answer 1

1

You are confusing Python instruction from documentation import jsbeautifier. In order to import this beautifier in javascript (client or nodejs) you need to do it this way:

import { js_beautify } from 'js-beautify'

However, I doubt you really want to do it this way, code beautification should probably not be part of your app.component.ts.

3
  • 1
    you may need its typing : npm i @types/js-beautify Oct 15, 2017 at 10:37
  • Guys, its working but I wonder why I was able to do: import 'rxjs/add/operator/map'; import 'hammerjs'; import 'prismjs'; in my app.component.ts ? Oct 15, 2017 at 19:54
  • 1
    You can do it because those modules exist. There is no jsbeautifier module you can import so it was not working.
    – dfsq
    Oct 15, 2017 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.