Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t导入Angular 4中需要json文件的npm包_Json_Angular_Webpack_Angular Cli - Fatal编程技术网

Can';t导入Angular 4中需要json文件的npm包

Can';t导入Angular 4中需要json文件的npm包,json,angular,webpack,angular-cli,Json,Angular,Webpack,Angular Cli,我重新安装了Angular 4项目,并尝试在其中加载npm包steem,如下所示: app.component.ts import {Component, OnInit} from '@angular/core'; import * as steem from 'steem'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.cs

我重新安装了Angular 4项目,并尝试在其中加载npm包
steem
,如下所示:

app.component.ts

import {Component, OnInit} from '@angular/core';
import * as steem from 'steem';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'app works!';

  ngOnInit() {
    steem.api.getAccounts(['test', 'test2'], function(err, response){
      console.log(err, response);
    });
  }
}
但是,出现以下错误:

Failed to compile.

./~/steem/lib/api/index.js
Module not found: Error: Can't resolve './methods' in '/Users/Stephan/Dev/kanzeon/node_modules/steem/lib/api'
 @ ./~/steem/lib/api/index.js 17:15-35
 @ ./~/steem/lib/index.js
 @ ./src/app/app.component.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
在我看来,这是因为它无法解析的
/methods
是一个JSON文件。Angular cli的webpack配置确实包含一个json加载程序(我已经安装了
json加载程序
npm包),但在加载程序中有一行
exclude:“node_modules”

我真的不想用我自己的Web包配置覆盖angular cli的Web包配置(他们隐藏其实现是有充分理由的,它的配置非常高效),但这确实给我的应用程序带来了问题

有没有办法确保我可以包含
steem
npm包,并让它在不重写webpack配置的情况下加载其json文件

steem js在内部需要JSON文件,因此需要配置JSON加载程序

因此,恐怕您必须扩展/覆盖angular cli的网页包配置。不幸的是,它看起来棱角分明

有可能吗

steem js在内部需要JSON文件,因此需要配置JSON加载程序

因此,恐怕您必须扩展/覆盖angular cli的网页包配置。不幸的是,它看起来棱角分明


有可能吗?

谢谢。从文档中我并不完全清楚钩子如何解决我的问题。我是否应该创建一个单独的npm模块,在构建期间有效地提供一个钩子来注入
steem
模块?我对angular cli没有任何经验:')钩子看起来很有希望解决您的问题,但我想它们不是……谢谢。从文档中我并不完全清楚钩子如何解决我的问题。我是否应该创建一个单独的npm模块,有效地提供一个钩子来在构建期间注入
steem
模块?我对angular cli没有任何经验:')钩子看起来很有希望解决您的问题,但我猜他们不是……由steemit团队解决,他们只是用js文件替换json……由steemit团队解决,他们只是用js文件替换json