在使用.mjs脚本和.js方面也需要一些帮助。
我有一个像这样的script.mjs文件。简化这里(脚本需要是.mjs文件)
import test from './test.js';
test();test.js看起来是这样的。这里再次简化,但它需要是.js文件:
const fs = require('fs');
const path = require('path');
const root = path.join(__dirname, '../../');
const statsPath = path.join(
root,
'somepath',
);
export function test() {
const localBuildStat = JSON.parse(
fs.readFileSync(statsPath, { encoding: 'utf8' }),
);
let assetSizes = {};
const assets = localBuildStat.assets;
assets.forEach((s) => {
// do something here
}
});
}当我试图运行script.mjs文件时,会得到以下错误:

你建议我怎么解决这个问题?提前感谢
发布于 2022-09-13 13:36:34
在公共场合使用module.exports
module.exports = function test() {
// ...
}https://stackoverflow.com/questions/73703918
复制相似问题