简体   繁体   English

app.js:3524 Uncaught ReferenceError: THREE not defined at Object../node_modules/three-bmfont-text/index.js

[英]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.

相关问题 Angular with Socket.io: Uncaught ReferenceError: WebSocket is not defined at Object../node_modules/engine.io-client/lib/transports/websocket.js - Angular with Socket.io: Uncaught ReferenceError: WebSocket is not defined at Object../node_modules/engine.io-client/lib/transports/websocket.js Three.js - 未捕获的 ReferenceError:未定义三个 - Three.js - Uncaught ReferenceError: THREE is not defined 未捕获的ReferenceError:app.js中未定义require:3 - Uncaught ReferenceError: require is not defined at app.js:3 未捕获的ReferenceError:未定义角度app.js - Uncaught ReferenceError: angular is not defined app.js Three.js - 未捕获的 ReferenceError:未定义 OBJLoader - Three.js - Uncaught ReferenceError: OBJLoader is not defined 错误 in./src/app.js 模块构建失败(来自./node_modules/babel-loader/lib/index.js):错误:找不到模块'@babel/preset-present-env' - ERROR in ./src/app.js Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module '@babel/preset-present-env' three.js-未捕获ReferenceError:未定义场景 - three.js-Uncaught ReferenceError: scene is not defined 未捕获的错误:模块构建失败(来自./node_modules/babel-loader/lib/index.js) - Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js) Webpack Uncaught ReferenceError:从bundle.js中删除node_modules后未定义require - Webpack Uncaught ReferenceError: require is not defined after removing node_modules from bundle.js 从 node_modules index.js 导入 class 定义 - import class definitions from node_modules index.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM