reactjs - “你可能需要一个额外的加载器来处理这些加载器的结果”(React Native)
问题描述
我正在开发一个带有TypeScript模板的Bare React Native音频播放器混合(Web 和 android)应用程序。在我实现了expo-av并尝试在网络上编译它之后,我得到了这个:
Failed to compile.
./node_modules/expo-av/build/Audio/Recording.js 134:46
Module parse failed: Unexpected token (134:46)
File was processed with these loaders:
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| this._canRecord = false;
| this._isDoneRecording = true;
> this._finalDurationMillis = finalStatus?.durationMillis ?? 0;
| _recorderExists = false;
|
webpack.config.js:
const createExpoWebpackConfigAsync = require('@expo/webpack-config');
module.exports = async function(env, argv) {
const config = await createExpoWebpackConfigAsync({
...env,
babel: {
dangerouslyAddModulePathsToTranspile: ['@ui-kitten/components']
}
}, argv);
return config;
};
包.json:
"dependencies": {
"react": "^16.13.1",
"react-native": "0.63.4",
...
}
"devDependencies": {
"@expo/webpack-config": "^0.12.58",
"@babel/core": "^7.8.4",
...
}
如果有帮助,这是我的存储库: https ://github.com/VelislavP/MeditationAppReactNative
使用 expo-av 的文件是:MeditationAppReactNative/src/screens/meditations.tsx
我该如何解决这个问题?提前致谢。
解决方案
编辑 node_modules 不是一个好的解决方案。这个问题是因为无效的合并运算符。我在 React Native 项目中从来没有这样做过,但我将在这里留下一个解决方案,帮助我在 React 项目中。我希望这对遇到类似问题的任何其他人有所帮助。
就我而言,加载新包很有帮助@babel/plugin-proposal-logical-assignment-operators
。
我正在使用@craco/craco
,所以加载这个包非常简单。
在我的 craco.config.js 文件中,我添加了这些行。
babel: {
plugins: [
"@babel/plugin-proposal-logical-assignment-operators"
],
},
您可以从此链接查看有关此问题的讨论的详细信息。
推荐阅读
- c# - C# ClientWebSocket 没有接收到所有数据包?
- mongodb - 在 MongoDB 和 Golang 中搜索 ObjectID > "xxxx"
- jupyter - 在 jupyter 工作,试图绘制时间序列
- mysql - 如何在 Laravel 中运行 mysql 查询
- podio - Podio 到 excel 导出收到 400 个响应
- javascript - 努力自动发布 Twitter 机器人帖子
- node.js - 通过 websockets(socket.io、nodejs、react-native)发送图像和视频
- google-chrome - Chrome v80 的 ASP .NET Core Web 应用程序对象引用错误
- java - KeywordAnalyzer 处理带有变音符号的单词的不同拼写
- angular - nginx 返回所有 Angular 文件(包括脚本)的 index.html 内容