我正在尝试在styled-components
模块中导入create-react-library
。但是,当我运行它时,出现以下错误消息:
Error: 'typeOf' is not exported by node_modules\react-is\index.js, imported by node_modules\styled-components\dist\styled-components.browser.esm.js
at C:\Users\roypo\Projects\Web Development\wiit-ui\node_modules\styled-components\dist\styled-components.browser.esm.js:1:9
1: import { typeOf, isElement, isValidElementType } from 'react-is';
^
2: import React, { useState, useContext, useMemo, useEffect, useRef, createElement, useDebugValue } from 'react';
3: import shallowequal from 'shallowequal';
我像这样导入styled-components
:
import styled from 'styled-components'
我将其添加到peerDependencies
和devDependencies
(以及常规依赖项)中,如下所示:
//code above
"peerDependencies": {
"react": "^16.0.0",
"styled-components": "^5.1.0"
},
"devDependencies": {
"microbundle-crl": "^0.13.10",
"babel-eslint": "^10.0.3",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.7.0",
"eslint-config-standard": "^14.1.0",
"eslint-config-standard-react": "^9.2.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-standard": "^4.0.1",
"gh-pages": "^2.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.4",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "^3.4.1",
"styled-components": "^5.1.0"
},
"dependencies": {
"styled-components": "^5.1.0"
}
(这不是故意的,只是格式问题)
仅使用create-react-app
时效果很好。
我该如何解决?预先感谢。
编辑
我使用以下命令安装了它:npm i --save styled-components
答案 0 :(得分:0)
我不太明白这里发生了什么,但我解决了这个问题,在我的 react-is
中添加了 package.json
作为依赖项。
npm i --save react-is
编辑:我想补充一点,我已删除,然后将 styled-components
重新添加到我的依赖项中,但没有任何改变。