[英]Object.defineProperty(exports, “__esModule”, { value: true });
Error when json import in typescript 在打字稿中导入json时出错
error message : Uncaught ReferenceError: exports is not defined 错误消息:未捕获的ReferenceError:未定义导出
books.ts books.ts
import data from './books.json';
class books{
//...code
constructor(){
//...code
}
}
books.js books.js
"use strict";
**Object.defineProperty(exports, "__esModule", { value: true });**
class books {
//...code
constructor() {
//...code
}
}
your code 你的代码
import data from './books.json';
implies you are running in a module. 意味着你在一个模块中运行。 To run modules on browsers you need a module bundler.
要在浏览器上运行模块,您需要一个模块捆绑器。 eg https://webpack.github.io/
例如https://webpack.github.io/
Quickstart on webpack with TypeScript https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html 使用TypeScript在webpack上快速入门https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.