question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript 2.4 Error: Variable StyledComponentClass from external module cannot be named.

See original GitHub issue

Version

2.1.1 Typescript: 2.4.2

Reproduction

Given a styled-component src/wrapper.tsx

import * as React from 'react';
import styled from 'styled-components';

const Wrapper = styled.header`
  background-color: red;
  height: 50px;
  width: 100%;
`

export default Wrapper;

and tsconfig.json

{
 "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "lib": ["dom", "es2015", "es2016"],
    "outDir": "dist",
    "baseUrl": "./src",
    "jsx": "react",
    "sourceMap": true,
    "declaration": true
  },
  "exclude": [
    "node_modules"
  ]
}

The following error occurs:

[ts] Exported variable 'Wrapper' has or is using name 'StyledComponentClass' from external module "/path/project/node_modules/styled-components/typings/styled-components" but cannot be named.

Steps to reproduce

Expected Behavior

Doesn’t throw error

Actual Behavior

Throws error

[ts] Exported variable 'Wrapper' has or is using name 'StyledComponentClass' from external module "/path/project/node_modules/styled-components/typings/styled-components" but cannot be named.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
Igorbekcommented, Aug 4, 2017

Ah, I though it was not exported, but it was. If you write your code that way, it should work:

import * as React from 'react';
import styled, { StyledComponentClass } from 'styled-components'; // <-- note additional export here

const Wrapper = styled.header`
  background-color: red;
  height: 50px;
  width: 100%;
`

export default Wrapper;

We cannot fix this on our side, that is TypeScript’s intended behavior, but the fix is under consideration.

4reactions
Igorbekcommented, Aug 4, 2017

Yes, that is annoying TS error that prevents writing declaration files when they use inferred types that are defined externally. There’re 2 issues here:

  1. StyledComponentClass is not exported
  2. The name should imported even if it’s not used explicitly

The first we can fix, and we will. The second you’d have fix yourself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type from external module cannot be named - Stack Overflow
I am getting a very strange typescript error and I have no clue why this is happening: I have a a function "cleanArgs"...
Read more >
False typescript error : WEB-42042 - YouTrack
The error is: TS4023: Exported variable 'selectedPrinterSelector' has or is using name 'Pages' from external module "[...]/UI" but cannot be named.
Read more >
Kent C. Dodds on Twitter: "@pelotom I did see that same ...
TS4023: Exported variable 'X' has or is using name 'Y' from external module 'a/file/path' but... I'm attempting to create a set of external...
Read more >
Parameter 'x' of public method from exported class...external ...
error : Parameter 'x' of public method from exported class...external module “z” but cannot be named. HandsomeChow 于 2021-09-09 09:42:19 发布 265 收藏....
Read more >
framework from aesthetic-suite - Giter VIP
JavaScript 4.11% CSS 0.01% HTML 1.69% TypeScript 86.78% EJS 7.41% react css ... and CSS variables for high performance, low filesize, and efficient...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found