报错信息
[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.
Original error: Cannot use import statement outside a module
报错原因
- 单独使用
rollup打包lodash,lodash是遵从commonjs规范。所以我借助了两个插件来解决commonjs规范的库在rollup中打包。pnpm add @rollup/plugin-commonjs @rollup/plugin-node-resolve -D - 我在
package.json文件中添加"type" :"module"就如上报错信息。
解决方法
在package.json 里添加 "type" :"commonjs" 就解决了, 我很疑惑,盼望大佬解惑。