关于nuxt2引入three.js页面刷新报错问题
刷新后页面提示:
require() of ES Module
three.js is treated as an ES module file as it is a .js file whose nearest parent package.json
contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename three.js to end in .cjs, change the requiring code to use dynamic import()
which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs"
in D:\XX\XXXXX\node_modules\three\package.json to treat all .js files as CommonJS
问题所在:
这与 nuxt 构建系统有关。使用第三方库时,应该将它们添加到 nuxt.config.js build.transpile
数组中,以便它可以作为 Babel 的依赖项包含在内。
build: {
transpile: ["three"]
}