[英]app.js:3524 Uncaught ReferenceError: THREE is not defined at Object../node_modules/three-bmfont-text/index.js
I am trying to use Three.js with three-bmfont-text to create text in 3D and give it a nice look using shaders.我正在尝试使用 Three.js 和 three-bmfont-text 来创建 3D 文本并使用着色器给它一个漂亮的外观。
I install three and three-bmfont-text through npm and import it in JS file:我通过npm安装三三bmfont-text并导入到js文件中:
import * as THREE from 'three';
const loadFont = require('load-bmfont');
const createGeometry = require('three-bmfont-text');
I run npm run dev and npm run watch and everything seems to work fine, but in chrome developer it logs the following error :我运行 npm run dev 和 npm run watch ,一切似乎都运行良好,但在 chrome developer 中,它记录了以下错误:
app.js:3524 Uncaught ReferenceError: THREE is not defined at Object../node_modules/three-bmfont-text/index.js app.js:3524 Uncaught ReferenceError: THREE not defined at Object../node_modules/three-bmfont-text/index.js
I tried to install and uninstall three and three-bmfont-text but nothing changes, what am I missing?我尝试安装和卸载三个和三个 bmfont-text 但没有任何变化,我错过了什么?
Maybe it helps somebody who finds this question.也许它可以帮助找到这个问题的人。 This one quite popular in google.
这个在谷歌很流行。
You need to add this in webpack ( link ):您需要在 webpack ( 链接) 中添加它:
plugins: [
new webpack.ProvidePlugin({
THREE: 'three'
})
]
If you are using next ( link ):如果您使用下一个( 链接):
config.plugins.push(
new webpack.ProvidePlugin({
THREE: 'three',
})
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.