我有一个Lerna项目,我试图将shared
文件夹中的react-native-web
组件共享到我的NextJS web
文件夹中。结构如下:
lerna.json
package.json
packages
shared
components
package.json
web
pages
next.config.js
package.json
当我进入web
并运行npm run dev
时,出现以下错误:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
static async getInitialProps ({ renderPage }) {
16 | AppRegistry.registerComponent('Main', () => Main)
17 | const { getStyleElement } = AppRegistry.getApplication('Main')
> 18 | const page = renderPage()
| ^ 19 | const styles = [
20 | <style dangerouslySetInnerHTML={{ __html: normalizeNextElements }} />,
21 | getStyleElement()
我的next.config.js
包含:
const withTM = require('next-transpile-modules')
module.exports = withTM({
transpileModules: ['@my-proj/shared'],
webpack: config => {
// Alias all `react-native` imports to `react-native-web`
config.resolve.alias = {
...(config.resolve.alias || {}),
'react-native$': 'react-native-web'
}
return config;
}
})
关于导致该错误的原因有什么想法?