【发布时间】:2016-10-07 18:54:13
【问题描述】:
我遇到了 webpack 告诉我的问题:
./app/app.tsx 中的错误 (4,25): 错误 TS2307: 找不到模块 './sample-data'。
我的导入看起来像这样:
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { InboxPane } from './components/Inbox';
import * as Samples from './sample-data';
最后这是我要导入的 sample-data.js 文件:
module.exports = {
"humans": {
"John Smith" : {
"conversations": [
{
"who": "bot",
"text": "Hello, can I take your order?",
"time": new Date(2016, 4, 5, 15, 10, 0, 0)
},
{
"who": "human",
"text": "Can I have a small meat-lovers pizza?",
"time": new Date(2016, 4, 5, 15, 10, 30, 0)
},
{
"who": "bot",
"text": "Where would you like it delivered?",
"time": new Date(2016, 4, 5, 15, 11, 0, 0)
},
{
"who": "human",
"text": "123 Sesame Street, Montreal, Canada",
"time": new Date(2016, 4, 5, 15, 11, 30, 0)
},
],
"orders": [
{
"time": new Date(2016, 4, 5, 15, 11, 45, 0),
"pizzas": [{
"toppings": ["Meat-Lovers"],
"size": "S"
}],
"price": 15,
"address": "321 Sesame Street, Montreal, Canada",
"status": "Confirmed" // status := Open -> Confirmed -> In The Oven -> Delivered
}
]
},
"Alan Foster" : {
"conversations": [
{
"who": "bot",
"text": "Hello, can I take your order?",
"time": new Date(2016, 4, 4, 20, 30, 0, 0)
},
{
"who": "human",
"text": "I would like to order an extra-large cheese pizza",
"time": new Date(2016, 4, 4, 20, 30, 15, 0)
},
{
"who": "bot",
"text": "Where would you like it delivered?",
"time": new Date(2016, 4, 4, 20, 30, 30, 0)
},
{
"who": "human",
"text": "123 Sesame Street, Montreal, Canada",
"time": new Date(2016, 4, 4, 20, 30, 45, 0)
},
],
"orders": [
{
"time": new Date(2016, 4, 4, 20, 31, 0, 0),
"pizzas": [{
"toppings": ["cheese"],
"size": "XL"
}],
"price": 15,
"address": "123 Sesame Street, Montreal, Canada",
"status": "Delivered" // status := Open -> Confirmed -> In The Oven -> Delivered
}
]
}
}
};
如果我将其更改为 sample-data.ts,我会被告知它不是一个模块。如何将其加载到我的 .tsx 文件中?
【问题讨论】:
-
所以你有
sample-data文件夹? -
没有 sample-data.js 与我要导入它的 app.tsx 文件位于同一文件夹中。
标签: javascript reactjs typescript