低版本node与swiper版本导致的错误
最近在nextjs项目中使用swiper,版本信息如下:
node版本12.9.1
"next": "11.1.0",
"swiper": "7.4.1",
项目打包后报错:
(node:159) ExperimentalWarning: The ESM module loader is experimental.
> Build error occurred
file:///shark/web-book/node_modules/swiper/react/use-isomorphic-layout-effect.js:1
import { useEffect, useLayoutEffect } from 'react';
^^^^^^^^^
SyntaxError: The requested module 'react' is expected to be of type Commonjs, which does not support named exports. Commonjs modules can be imported by importing the default export.
For example:
import pkg from 'react';
const { useEffect, useLayoutEffect } = pkg;
at ModuleJob._instantiate (internal/modules/esm/module_job.js:97:21)
at async ModuleJob.run (internal/modules/esm/module_job.js:143:20)
at async Loader.import (internal/modules/esm/loader.js:182:24) {
type: 'SyntaxError'
}
重点错误信息The requested module 'react' is expected to be of type Commonjs, which does not support named exports. Commonjs modules can be imported by importing the default export
意思就是打包环境还不支持EMS包
解决方案:
- 升级node版本到14.x
- 把swiper版本降到6.x版本
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。