我尝试使用react v17和webpack externals,但有一些错误:
react-jsx-runtime.production.min.js:9 Uncaught (in promise) TypeError: Cannot read property 'ReactCurrentOwner' of undefined
at Object../node_modules/react/cjs/react-jsx-runtime.production.min.js (react-jsx-runtime.production.min.js:9)
at l (bootstrap:19)
at Object../node_modules/react/jsx-runtime.js (jsx-runtime.js:4)
at l (bootstrap:19)
at load script:2
at Function.l.a (async module:58)
at Object../src/index.tsx (load script:2)
at l (bootstrap:19)
at startup:4
at startup:4
enter image description here
我的朋友们:
// tsconfig.json
{
"include": ["src/**/*"],
"compilerOptions": {
"jsx": "react-jsx",
"strict": true,
"sourceMap": true,
"target": "ESNext",
"types": ["webpack-env"],
"baseUrl": "./",
"paths": {
"src/*": ["./src/*"]
},
"allowSyntheticDefaultImports": true,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
]
}
}
// webpack.config.js
{
externalsType: 'script',
externals: {
react: ['https://cdn.bootcdn.net/ajax/libs/react/17.0.2/umd/react.production.min.js', 'React'],
'react-dom': ['https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js', 'ReactDOM'],
},
}
这个问题可能是由tsconfig.compilerOptions.jsx = 'react-jsx'引起的,但是如何通过使用'react-jsx'配置来解决这个问题呢?
1条答案
按热度按时间l7wslrjt1#
“at Object../node_modules/react/cjs/react-jsx-runtime.production.min.js(react-jsx-runtime.production.min.js:9)”的名称为“cjs”。如果你想通过cdn导入,你应该使用umd。