typescript / webpack報錯“can only be default-imported using the 'esModuleInterop' flag


原因:This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
解決:

import request = require('request');
//或
import * as request from 'request';

后來在webpack時報錯很多modules里文件的這個錯:

解決:
在tsconfig.json里添加

"esModuleInterop": true


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM