Angular无法导入库 [英] Angular not able to import library
问题描述
我正在从> https://www.npmjs.com/package安装js-beautify/js-beautify
通过 npm install js-beautify --save
然后将导入添加到我的app.component.ts
Then adding import to my app.component.ts
文档说
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
我也尝试了导入
import '../../node_modules/js-beautify/js/lib/beautify.js'
我正在使用角度cli 2/4
I'm using angular cli 2/4
推荐答案
您正在混淆文档 import jsbeautifier
中的Python指令.为了在javascript(客户端或nodejs)中导入此美化工具,您需要这样做:
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'
但是,我怀疑您是否真的想这样做,代码美化可能不应该是您的 app.component.ts
的一部分.
However, I doubt you really want to do it this way, code beautification should probably not be part of your app.component.ts
.
这篇关于Angular无法导入库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!