简体   繁体   English

Object.defineProperty(exports,“__ myModule”,{value:true});

[英]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/

More 更多

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.

相关问题 Object.defineProperty是否检查属性是否已定义? - Does Object.defineProperty check if the property is defined? 原型上的 Object.defineProperty 阻止 JSON.stringify 对其进行序列化 - Object.defineProperty on a prototype prevents JSON.stringify from serializing it 获取postgresql表中jsonb对象的所有键,其中值为true - Get all keys of jsonb object in postgresql table where value is true NodeJS:将js对象写入文件并进行导出 - NodeJS: Write a js object to file and do exports 如果为True,如何检查JSON对象布尔值,然后从php模板创建网页 - How to check a JSON object Boolean value that then creates a webpage from a php template if True 如果 object 中的值为真并且单击复选框时,我想在页面加载时填写复选框 - I want to fill the checkbox on page load if the value is true in the object and when the checkbox is clicked 导出函数中Node.js中响应正文的未定义值。 - Undefined Value For Response Body in Node.js in an Exports Function. 意外的字符(“ a”(代码97)):应为有效值(数字,字符串,数组,对象,“真”,“假”或“空”) - Unexpected character ('a' (code 97)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') ValueError:使用参数lines = True读取熊猫中的json时的预期对象或值 - ValueError: Expected object or value when reading json in panda using parameter lines=True Boolean 值始终返回 true - Boolean value always returns true
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM