[React Native] the package itself specifies a ‘main’ module field that could not be resolved 解決方式

錯誤訊息

While trying to resolve module expo-font from file '....', the package '....' was successfully found.However, this package itself specifies a 'main' module field that could not be resolved ('...'). Indeed, none of these files exist: ....
unknown [React Native] the package itself specifies a 'main' module field that could not be resolved 解決方式

解決方式

打開 node_modules/metro/src/integration_tests/metro.config.js,加入 resolver.sourceExts:['jsx', 'js', 'ts', 'tsx']transformer.experimentalImportSupport: false

resolver: {
  sourceExts: ['jsx', 'js', 'ts', 'tsx'],
},
transformer: {
    experimentalImportSupport: false,
}

或者也可以安裝這個第三方庫,會幫你自動完成這些設定:https://www.npmjs.com/package/@expo/metro-config

image 36 [React Native] the package itself specifies a 'main' module field that could not be resolved 解決方式

更多 metro.config.js 的 API 可以查看官方文檔:https://facebook.github.io/metro/docs/configuration/

0 0 評分數
Article Rating
訂閱
通知
guest

0 Comments
在線反饋
查看所有評論