Visual Studio构建模块但Webpack失败并显示“未找到模块”

时间:2017-05-18 10:00:44

标签: visual-studio reactjs typescript webpack visual-studio-2017

我正在.tsx文件中导入这样的自定义模块:

import { LinkContainer } from './typings/LinkContainer';

Visual Studio构建没有问题但是当我尝试运行webpack时出现以下错误:

ERROR in ./Features/Menu/Menu.tsx
Module not found: Error: Can't resolve './typings/LinkContainer' in 'C:\Users\<user>\Documents\<solution>\<project>\Features\Menu'
 @ ./Features/Menu/Menu.tsx 19:22-56
 @ ./Features/App.tsx
 @ ./Features/index.tsx
 @ multi react-hot-loader/patch ./Features/index.tsx

LinkContainer.d.ts的文件内容:

import { ComponentClass } from "react";
import { NavLinkProps } from "react-router-dom";

type LinkContainer = ComponentClass<NavLinkProps>;
export const LinkContainer: LinkContainer;

1 个答案:

答案 0 :(得分:0)

问题是只加载了类型定义而不是模块本身。解决了import { LinkContainer } from 'react-router-bootstrap';。您可以在此处阅读我的答案,了解自定义类型,这是首先创建自定义类型的原因:https://stackoverflow.com/a/44046969/3850405