问题描述
我一直在尝试通过 npm
安装 babylonjs.我已经建立了一个新项目并从 npm init
开始.之后,我根据他们的文档使用 npm install babylonjs --save
安装了 babylonjs.现在我创建了一个 JavaScript 文件来使用 import * as BABYLON from 'babylonjs';
导入他们的模块.当我打开控制台时,它向我抛出此错误:Uncaught SyntaxError: Cannot use import statement outside a module
.
I've been trying to install babylonjs via npm
. I've set up a new project and started with npm init
. After that I installed babylonjs with npm install babylonjs --save
according to their documentation.Now I created a JavaScript file to import their module using import * as BABYLON from 'babylonjs';
. When I open the console it throws me this error: Uncaught SyntaxError: Cannot use import statement outside a module
.
由于我对它比较陌生,所以我不太确定我是否遗漏了重要的一步.我不想使用他们的 CDN,因为我无法一直访问互联网.
Since I'm relatively new to it I'm not quite sure if I'm missing an important step. I don't want to use their CDN, because I won't have access to the internet all the time.
提前致谢!
推荐答案
我建议使用 es6 包,它更适合使用 es6 样式的导入.
I would recommend using the es6 packages, which fit better when using es6-style imports.
这里是文档:
https://doc.babylonjs.com/features/es6_support
这篇关于“不能在模块外使用导入语句"使用 npm 安装 babylonjs 后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!