【问题标题】:"You may need an additional loader to handle the result of these loaders" (React Native)“您可能需要一个额外的加载器来处理这些加载器的结果”(React Native)
【发布时间】:2021-02-04 21:50:30
【问题描述】:

我正在开发一个带有 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;
};

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

我该如何解决这个问题? 提前致谢。

【问题讨论】:

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


    【解决方案1】:

    编辑 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

    【讨论】:

      【解决方案2】:

      好的,我解决了这个问题。现在它编译了!

      实际问题是:

      ./node_modules/expo-av/build/Audio/Recording.js 134:46
      Module parse failed: Unexpected token (134:46)
      

      于是我去了Recording.js并改了:

       this._finalDurationMillis = finalStatus?.durationMillis ?? 0;
      

      到这里:

      this._finalDurationMillis = finalStatus.durationMillis;
      

      而其他所有出现此类错误的文件都是问号的错。

      我认为这与我的项目使用 Typescript 模板和 expo-av 下载自身带有 typescript 配置的事实有关,但由于某种原因,它位于 .js 文件中,并且 js 不喜欢“?。 "(如果您不确定是否存在某些内容,则在 typescript 中使用)因此,现在通过删除它,应用程序可以正常工作。

      【讨论】:

      • 将需要修复 node_modules 中的此类类型错误?您找到了任何其他通用解决方案吗?请建议
      猜你喜欢
      • 2020-12-04
      • 2020-04-05
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2022-11-06
      • 2020-09-12
      • 2021-08-05
      • 1970-01-01
      相关资源
      最近更新 更多