模块未找到:错误:无法在角6解决“./package”

问题描述 投票:5回答:3

我使用Angular 6scraperjs

在我的组件文件,使用实例中所给出的代码一样

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

import scraperjs from 'scraperjs';

@Component({
  selector: 'app-express',
  templateUrl: './express.component.html',
  styleUrls: ['./express.component.css']
})
export class ExpressComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    this.aliExpress();
  }

  aliExpress() {
    console.log('loaded ali express');

    scrapperjs.StaticScraper.create('https://news.ycombinator.com')
      .scrape(function ($) {
        return $('.title a').map(function () {
          return $(this).text();
        }).get();
      }).then(function (news) {
      console.log(news);
    });
  }

}

但它给错误的

Failed to compile.

./node_modules/cheerio/index.js 
Module not found: Error: Can't resolve './package' in '/home/user/code/angular/ali-express/node_modules/cheerio'
angular angular6 cheerio
3个回答
0
投票

npm install

命令来安装依赖的包。我认为,依赖的包安装不正确。


0
投票

您正在使用require()加载这不加载在角文件的标准方式的文件。在这里,它会尝试在运行时加载,但无法找到它。

请尝试用进口加载它。如果还是不行,请尝试main.ts加载它。我不知道,但我装了hammerjs同样的方式。


0
投票

从您的解决方案文件夹结构中删除nodeModules,然后尝试安装NPM-安装

© www.soinside.com 2019 - 2024. All rights reserved.