2022-02-08   


按照Three官方文档进行操作:
https://threejs.org/docs/#manual/zh/introduction/Installation

// 方式 1: 导入整个 three.js核心库
import * as THREE from 'three';

const scene = new THREE.Scene();

结果webpack build报错
export 'default' (imported as 'Three') was not found in 'three'
用的vscode,鼠标点过去,居然是c盘的ts文件,而不是当前项目的node_modules, 看文件夹创建日期也是npm install three安装时的日期,但是我既没有全局安装然后这也不是npm的全局node_modules路径,于是就把路径Google一下,查到了原因,原来是vscode的一个功能:
https://code.visualstudio.com/docs/nodejs/working-with-javascript#_typings-and-automatic-type-acquisition
官方原话:

Many popular libraries ship with typings files so you get IntelliSense for them automatically. For libraries that do not include typings, VS Code's Automatic Type Acquisition will automatically install community maintained typings file for you.

草了,对于不包含类型文件的库,会自动安装社区维护的类型文件。
问题就出在这里。那么就禁用这个功能吧,在首选项里搜索typescript.disableAutomaticTypeAcquisition,勾选。 然后鼠标再点过去,文件是当前项目node_modules下的了。npm run build, 没有报错了。

Q.E.D.


我并不是什么都知道,我只是知道我所知道的。