我在我的Node应用程序中使用ES6 import语句和汇总并遇到困难。例如,在尝试加载fs时:
import * as fs from 'fs';
并尝试使用:
fs.writeFile(...);
我收到错误:
Uncaught (in promise) TypeError: Cannot read property 'writeFile' of undefined
我的汇总配置:
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
export default {
input: 'js/index.js',
output: {
file: 'build/bundle.js',
format: 'iife',
sourcemap: 'inline'
},
plugins: [
resolve(),
commonjs()
],
external: [
'fs'
]
};