我正在尝试在我的 React v16.8.1 中添加 JW Player v1.1.3 实例。
我运行命令
yarn add @jwplayer/jwplayer-react
来安装播放器。
尝试使用以下命令导入播放器后:
import JWPlayer from "@jwplayer/jwplayer-react";
我收到以下错误消息:
./node_modules/@jwplayer/jwplayer-react/lib/jwplayer-react.js
Module parse failed: Unexpected token (2:9801)
You may need an appropriate loader to handle this file type.
我重新格式化了文件的代码(发生错误的位置)
./node_modules/@jwplayer/jwplayer-react/lib/jwplayer-react.js
以获取有关错误到底在哪里的更多详细信息,然后我得到了:
Failed to compile.
./node_modules/@jwplayer/jwplayer-react/lib/jwplayer-react.js
Module parse failed: Unexpected token (641:16)
You may need an appropriate loader to handle this file type.
| i().has(r) && (t[r] = e[r]);
| }),
| { ...e.config, ...t, isReactComponent: !0 }
| );
| })(t)),
@ ./app/front/react/containers/admin/email_template/edit.jsx 4:0-48
@ ./app/front/packs/react/admin.js
@ multi (webpack)-dev-server/client?http://localhost:3035 ./app/front/packs/react/admin.js
所以问题(正如我认为的)正是在这一行(641)中:
| { ...e.config, ...t, isReactComponent: !0 }
注意:我无法更新
react
的版本
1.安装babel加载器 通过运行命令:npm install babel-loader @babel/core @babel/preset-env @babel/preset-react --save-dev 2.通过以下文件配置webpack:webpack.config.js,并在该文件中添加一条规则,如 在此输入代码
模块:{
规则:[
{
测试:/.jsx?$/,
排除:/node_modules/,
使用: {
加载器:'babel-loader'
}
}
]
}
` 3.检查依赖项,例如是否安装了正确的版本,如下所示
enter code here
@jwplayer/jwplayer-react
4.重建并重启:
npm run build
npm start
谢谢你