簡體   English   中英

node_modules 錯誤未導出統計信息 - 匯總

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM