-
Notifications
You must be signed in to change notification settings - Fork 1.2k
import fails with 'no default export' #8
Comments
Have you tried:
|
Yes. But I have hundreds of files like this. I thought TypeScript was a superset of JavaScript? |
Add |
^ + IME change tsconfig.json > compilerOptions.module to 'es2015'. That's the configuration I've been using on my React/TS projects, allows for the usual default import syntax that most have become accustomed to. |
This did not work. Now I am getting this error:
Here is the entire app:
Changing to this fixes it:
|
This has to do with the CommonJS/ES module interop, which is not specified in the ECMAScript standard. In the near future, I believe that Babel and TypeScript will be more aligned on this. |
The funny thing is that these are all runtime errors. It's a bit ironic that after converting my code base to TypeScript, I'm now plagued with runtime errors. |
Same issue.
This is temporary solution. |
I just had the same error, this was the first hit on a google search. Was strange to me as I was importing above just fine and then saw the difference: import User from "user"; had the error. This: import {User} from "user"; did not. Might help someone else. |
Try this |
@wk-j it works.thanks |
@wk-j Your solution breaks my import of moment.js. |
@Mnuzz You can import moment like this
|
Apparently not. I'll set up a sample project and show you what happens. |
Neither "allowSyntheticDefaultImports" nor "esModuleInterop" works in my case. Tried fresh CRA with react-scripts-ts and setting up from scratch with Typescript 2.7.2. |
@Mnuzz did you get around to put together the sample project? |
…eScript-React-Starter#8 (comment)) htbkoo/CssToAndFromReact
need both
|
@gogowings Thanks it's work. |
I have set @wtilton |
Try this : |
Apparently adding this helps. Works locally microsoft/TypeScript-React-Starter#8 (comment)
@gogoyqj Thanks. I solved this problem. I hope my config helps other. "compilerOptions": {
"sourceMap": true,
"module": "esnext",
"moduleResolution": "node",
"target": "es5",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"typeRoots": [
"./node_modules/@types/"
],
} |
Following the README, you are supposed to make the following changed in {
- "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
+ "extends": [],
+ "defaultSeverity": "warning",
"linterOptions": {
"exclude": [
"config/**/*.js",
"node_modules/**/*.ts"
]
}
} from https://github.com/Microsoft/TypeScript-React-Starter#overriding-defaults You can also simply add: + "defaultSeverity": "warning", And the issue should go simply be a warning in the console. |
Combination of |
This import works fine under babel:
import React from "react";
But under TypeScript it complains of:
(1,8): error TS1192: Module '"/Volumes/repos/tc-web-ts/node_modules/@types/react/index"' has no default export.
The text was updated successfully, but these errors were encountered: