6

In ES6-ifying some TypeScript code (the project I'm working runs in both the browser and a Node server, I'd like to tree-shake the browser bundle), I'm trying to eliminate uses of require and only use import. But when I do this...

import * as request from 'request';

and subsequently call request(), I get runtime errors in Node (after using babel to make the code ES5, and thus Node, compatible):

TypeError: request is not a function

On the other hand, if I do this:

import request from 'request';

then the TypeScript compiler complains with

error TS1192: Module '"<mypath>/node_modules/@types/request/index"' has no default export.

If I manually change the compiled JS code to use import request from 'request';, it actually works fine... how can I force the TS compiler to accept this code and just pass it through?

1

2 Answers 2

4

Can you try Add allowSyntheticDefaultImports: true to your 

tsconfig.json

 seems like still an open issue in Typescript.

Sign up to request clarification or add additional context in comments.

Comments

0

Basically you need remove comment in tsconfig.json at line 46, because default ts config file have this option but it's commented by default

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.