styled-components not working with create-react-library

Viewed 701

I'm trying to import styled-components in a create-react-library module. However, when i run it I get the following error message:

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';

I import styled-components like:

import styled from 'styled-components'

I added it to both the peerDependencies and devDependencies (and the regular dependencies) as follows:

"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"
}

(it's not intended, it's just a formatting problem)

It works fine when I use just create-react-app.

How can I fix it? Thanks in advance.

EDIT

I installed it with the following command: npm i --save styled-components

1 Answers

I don't really get what's going on here, but I solved this issue adding react-is as a dependency in my package.json.

npm i --save react-is

EDIT: I would like to add that I've removed and then re-added styled-components to my dependencies, but nothing changed.

Related