reactjs - "You may need an additional loader to handle the result of these loaders"( native react )

标签 reactjs react-native audio babel-loader expo-av

我正在使用 TypeScript 模板开发一个 Bare React Native 音频播放器混合应用(网络和安卓)。 在我实现 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;
};

package.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"
  ],
},

你可以从这个链接看到关于这个问题的详细讨论。

https://github.com/facebook/create-react-app/issues/9908

关于reactjs - "You may need an additional loader to handle the result of these loaders"( native react ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66054352/

相关文章:

javascript - React 无状态组件中的 Ajax 调用

javascript - 无法在我的组件中调用 redux 操作

javascript - 每当我移动到不同的标签屏幕时,它都会显示错误 "Accessing the state property of the route object is not supported"

android - 关闭并重新打开我的应用程序后,无法播放URI中的音频

c++ - 为什么从 WAV 文件读取的 SubChunk2Size 值等于 3452816845?

javascript - 如何识别 ReactJS Material-UI 中所选 <MenuItem/> 的主要文本?

javascript - React-这显示了填充状态,但 this.state 是空的

windows-phone-7 - WP7播放声音-播放完声音时得到通知

reactjs - 找不到模块 'react-faq-component' 的声明文件

react-native - 如何找到可能的未处理的 Promise Rejection 的来源