遵循 React 网站中提到的从 React 16 迁移到 React 17 的所有步骤后 删除反应导入后
我看到以下错误
Uncaught ReferenceError: React is not defined
Babel.config.js
module.exports = function(api) {
api.cache(true);
const presets = [
'@babel/preset-env',
["@babel/preset-react", {"runtime": "automatic"}]
];
const plugins = [
['@babel/plugin-proposal-class-properties'],
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
["@babel/plugin-transform-react-jsx", {
"runtime": "automatic"
}]
];
const env = {
test: {},
cucumber: {
plugins: [
'@babel/plugin-transform-regenerator',
[
'@babel/plugin-transform-runtime',
{
regenerator: true,
},
],
],
},
cypress: {
plugins: ['istanbul'],
},
};
return {
presets,
plugins,
env,
};
};
开发依赖
"@babel/plugin-transform-react-jsx": "7.23.4",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
"@babel/plugin-proposal-optional-chaining": "^7.12.1",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.24.0",
"@babel/preset-react": "^7.23.3",
反应版本:17.0.2
React 16 到 17 的迁移我使用了以下所有步骤: https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
这里也一样。从 React 16 升级到 React 19,我得到了
React is not defined
ReferenceError: React is not defined
所有未导入 React 的地方。 React 19 不应该再出现这种情况。我猜问题出在从 React 16 迁移到 React 19 的过程中,而且它在某种程度上是内部的。
非常感谢任何帮助!