【问题标题】:Angular2/4 Module not found: Error: Can't resolve 'three' in '..\app' resolve 'three' in '..\app'找不到Angular2 / 4模块:错误:无法解析“..\app”中的“三个”解析“..\app”中的“三个”
【发布时间】:2017-11-24 04:49:49
【问题描述】:

我是 angular 和 typescript 的新手,我正在努力导入 @types/three npm 包,我只是创建了一个新的 angular 项目,我尝试导入并使用这三个包,但我一直收到此错误

Module not found: Error: Can't resolve 'three' in 'E:\wamp64\www\pro-website-angular5\src\app'

我一定是在做一些新的错误,但我不知道,这是我的代码

import { Component } from '@angular/core';
import * as THREE from 'three';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{
  title = new THREE.Vector3(1,1,1);

}

【问题讨论】:

  • 路径“三”作为该文件的相关路径是否正确?

标签: node.js angular typescript npm


【解决方案1】:

首先安装所需的包。

yarn add three @types/three

然后从"three"导入Vector3

import { Component } from '@angular/core';
import { Vector3 } from "three";

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

}

【讨论】:

  • 谢谢你,成功了。我安装了纱线,然后运行这个命令行,奇怪的是因为我已经安装了 npm。
猜你喜欢
  • 2018-06-01
  • 2017-07-31
  • 2020-10-15
  • 2023-01-15
  • 2018-08-13
  • 2022-09-26
  • 1970-01-01
相关资源
最近更新 更多