我的工作是一个裸反应本地音频播放器混合(网络和安卓)应用程序与TypeScript模板。在我实现了expo并试图在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
使用expo-av的文件是:MeditationAppReactNative/src/screens/meditations.tsx。
我该怎么解决这个问题?提前谢谢。
发布于 2021-02-10 07:39:22
好吧,我解决了问题。现在它编译了!
实际问题是:
./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;每一个其他的文件,如果有这样的错误,都是问号的错。
我认为这与我的项目与类型记录模板有关,而expo-av使用类型记录配置下载了自己,但出于某种原因,它位于一个.js文件中,js不喜欢“?”(如果您不确定有什么东西存在,js不喜欢“?”),所以现在删除它就可以了。
发布于 2021-08-03 22:18:40
编辑node_modules不是一个好的解决方案。这个问题是由于无效的合并运算符。我从来没有做过这样的反应本土项目,但我将离开这里,一个解决方案帮助我在反应项目。我希望这会对其他面对类似问题的人士有所帮助。
在我的例子中,加载一个新的包@babel/plugin-proposal-logical-assignment-operators很有帮助。
我使用的是@craco/craco,所以加载这个包非常简单。
在我的craco.config.js文件中,我添加了这些行。
babel: {
plugins: [
"@babel/plugin-proposal-logical-assignment-operators"
],
},您可以从这个链接中看到有关此问题的详细讨论。
https://stackoverflow.com/questions/66054352
复制相似问题