[英]Stats is not exported by node_modules error - Rollup
我正在尝试将 stats.js(一点 fps 计数器)添加到我的 three.js 场景中。 该项目使用汇总来捆绑所有内容,并且在尝试像这样导入 Stats 后我不断收到此错误:
import { Stats } from 'stats.js'
错误内容如下:
[!] Error: 'Stats' is
not exported by node_modules\stats.js\build\stats.min.js, imported by src\main.js
我的汇总配置如下所示:
import resolve from '@rollup/plugin-node-resolve'; // locate and bundle dependencies in node_modules (mandatory)
import { terser } from "rollup-plugin-terser"; // code minification (optional)
export default {
input: 'src/main.js',
output: [
{
format: 'umd',
name: 'LIB',
file: 'build/main.js'
}
],
plugins: [ resolve(), terser() ]
};
Stats 在 stats.js 中导出,如下所示:
export { Stats as default };
我一直在浏览关于 github 的错误报告,我不确定它们是否相关 - 感到困惑 - 有人知道吗?
编辑:根据最初的答案,我尝试使用:
import * as Stats from 'stats.js'
我收到错误消息:
Uncaught TypeError: Cannot set property 'Stats' of undefined
引用这一行:
(function(f,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"===typeof define&&define.amd?define(e):f.Stats=e();})(undefined,function(){var f=function(){function e(a){c.appendChild(a.dom);return a}function u(a){for(var d=0;d<c.children.length;d++)c.children[d].style.display=d===a?"block":"none";l=a;}var l=0,c=document.createElement("div");c.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000";c.addEventListener("click",function(a){a.preventDefault();
__
我试过了:
const Stats = require('stats-js');
并收到错误消息:
Uncaught ReferenceError: require is not defined
__
我试过了:
import Stats from 'stats-js'
得到了这个:
(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
stats-js (imported by src\main.js)(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
stats-js (guessing 'Stats')
我听起来这最后一个错误是最有用的? 我按照错误消息中的链接进行操作,但仍然无法修复它。
该库不提供 es6 默认导出。
import * as Stats from 'stats-js'
// or
const Stats = require('stats-js')
// or
import Stats from 'stats-js'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.