From 98f9c132c88386a6dc7e13d6a11ab257be3e594c Mon Sep 17 00:00:00 2001 From: ysy945 <79794654+ysy945@users.noreply.github.com> Date: Sun, 7 Aug 2022 23:03:50 +0800 Subject: [PATCH] add judgment on vite packaging results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "React. CreateElement: type is invalid..." error will appear when using "vite" to package the react project The module obtained by using “import("xxx").then (module = > console.log (module))“ syntax in vite will be marked as "symbol (symbol. Tostringtag)": "module" The judgment in the 'resolve' function is "__esmodule: true", so the packaged user of "vite" should add the judgment after "vite" packaging, otherwise the packaged user of "vite" will not be able to use --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 5864dc33..82edfadc 100644 --- a/src/index.js +++ b/src/index.js @@ -90,7 +90,11 @@ function loadMap(obj) { } function resolve(obj) { - return obj && obj.__esModule ? obj.default : obj; + const symbolKey = Object.getOwnPropertySymbols(obj).find(key => key.toString() === 'Symbol(Symbol.toStringTag)') + if(obj.__esModule || obj[symbolKey]==='Module'){ + return obj.default + } + else return obj } function render(loaded, props) {