“你可能需要一个额外的加载器来处理这些加载器的结果”(React Native)

jslywgbw  于 6个月前  发布在  React
关注(0)|答案(2)|浏览(57)

我正在使用TypeScript模板开发一个Bare React Native音频播放器混合(Web和Android)应用程序。在我实现Type-av并尝试在Web上编译它之后,我得到了这个:

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
使用MeditationAppReactNative/src/screens/meditations.tsx的文件是:
我该怎么解决这个问题?先谢谢你了。

thigvfpy

thigvfpy1#

编辑node_modules不是一个好的解决方案。这个问题是因为nullish合并运算符。我在React Native项目中从未这样做过,但我会在这里留下一个在React项目中帮助我的解决方案。我希望这能帮助任何面临类似问题的人。
在我的例子中,加载一个新的包@babel/plugin-proposal-logical-assignment-operators很有帮助。
我使用的是@craco/craco,所以加载这个包非常简单。
在我的craco.js.js文件中,我添加了这些行。

babel: {
  plugins: [
    "@babel/plugin-proposal-logical-assignment-operators"
  ],
},

字符串
你可以从这个链接看到关于这个问题的讨论细节。
https://github.com/facebook/create-react-app/issues/9908

3htmauhk

3htmauhk2#

[THIS只是为了补充信息,因为我找到了问题的根源]
实际问题是:

./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模板的事实有关,并且Tumbl-av下载了自己的typescript配置,但出于某种原因,它在.js文件中,js不喜欢“?."(如果你不确定某些东西存在的话,在typescript中使用),所以现在通过删除它,应用程序可以工作。

相关问题