Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile with typescript declaration true #707

Closed
guilhermegregio opened this issue Jun 7, 2018 · 8 comments
Closed

Compile with typescript declaration true #707

guilhermegregio opened this issue Jun 7, 2018 · 8 comments
Assignees

Comments

@guilhermegregio
Copy link

  • emotion version: 9.2.1
  • react version: 16.3.2

What you did:
I created a ui library with Typescript, and build not work with tsc

my tsconfig.json file

{
  "compilerOptions": {
    "outDir": "build/lib",
    "baseUrl": "src",
    "rootDir": "src",
    "module": "commonjs",
    "target": "es5",
    "lib": ["es6", "es5", "dom"],
    "sourceMap": true,
    "allowJs": false,
    "jsx": "react",
    "moduleResolution": "node",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "declaration": true,
    "preserveConstEnums": true
  },
 ...
}

What happened:
I use declaration: true in tsconfig.json file to generate the type definition for my components but the compiler fails with the following message

node_modules/create-emotion-styled/types/index.d.ts:5:8 - error TS1192: Module '"../node_modules/@types/react/index"' has no default export.

5 import React, { ComponentClass, ReactHTML, ReactSVG, Ref, SFC } from 'react';
         ~~~~~


node_modules/create-emotion-styled/types/react.d.ts:4:8 - error TS1192: Module '"../node_modules/@types/react/index"' has no default export.

4 import React, { ComponentClass, Ref, SFC } from 'react';
@Ailrun
Copy link
Member

Ailrun commented Jun 7, 2018

Thank you for reporting issue, @guilhermegregio! Could you try allowSyntheticDefaultImports option and let me know whether it works or not?

@guilhermegregio
Copy link
Author

guilhermegregio commented Jun 7, 2018

@Ailrun tks this works for building, but when i use my lib in another project it does not work.

When i run return this error:

../node_modules/ems-ui/node_modules/emotion/types/index.d.ts' not found.

Any suggestions?

@Ailrun
Copy link
Member

Ailrun commented Jun 7, 2018

Could you give me a minimal repoducible repo? I cannot get anything from the error...
The file does exist, doesn't it?

@guilhermegregio
Copy link
Author

guilhermegregio commented Jun 7, 2018

I create this repo
https://github.com/guilhermegregio/test-ui-lib

see if you can help me.

The error occurs when you run npm start on use-lib package

@Ailrun
Copy link
Member

Ailrun commented Jun 8, 2018

@guilhermegregio
In your repository, tsconfig.json has problem so that it cannot find valid node_modules directory.
When I change packages/ui-lib/tsconfig.json to use "outDir": "build", and packages/ui-lib/package.json with "main": "build/index.js", "types": "build/index.d.ts",, npm run start (or npm start) emits different error, namely, about default import of react.
This also can be resolved with "allowSyntheticDefaultImports": true, in packages/use-lib/tsconfig.json.

However, this propagation of "allowSyntheticDefaultImports": true, does not look so good, so removing this would be preferable.

@guilhermegregio
Copy link
Author

@Ailrun
i ran with your changes of allowSyntheticDefaultImports and it worked fine to me.

@Ailrun
Copy link
Member

Ailrun commented Jun 11, 2018

@guilhermegregio My PR is published as v9.2.3. Could you check it? If it works fine, could you close this issue?

@guilhermegregio
Copy link
Author

@Ailrun i ran with v9.2.3 and it worked fine to me. Tks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants