【问题标题】:Cannot resolve NPM module which seems to have installed successfully无法解析似乎已成功安装的 NPM 模块
【发布时间】:2016-09-07 13:37:06
【问题描述】:

我已经安装了几个模块在做npm install --save ng2-redux redux redux-actions redux-promise。如果我这样做npm list | grep "redux",我会得到:

├── ng2-redux@3.0.5
├─┬ redux@3.5.2
├─┬ redux-actions@0.12.0
├─┬ redux-promise@0.5.3

在我的package.json 我也可以找到它们:

"dependencies": {
  ...

  "ng2-redux": "3.0.5",
  "redux": "3.5.2",
  "redux-actions": "0.12.0",
  "redux-promise": "0.5.3",

  ...
}

问题是虽然ng2-reduxredux 都可以正常工作:

import { applyMiddleware } from 'redux';
import { NgRedux, select } from 'ng2-redux';

redux-actionsredux-promise 在尝试导入它们时都会抛出 Cannot resolve file 'redux-actions'/'redux-promise',它同时出现在 IDE (WebStorm 11.0.4) 和 Webpack 中:

import { createAction } from 'redux-actions';
import promiseMiddleware from 'redux-promise';

错误说:

ERROR in ../src/.../app.component.ts
(8,31): error TS2307: Cannot find module 'redux-promise'.

不过……

import 'redux-actions';
import 'redux-promise';

...工作得很好。

我已经尝试删除 node_modules 文件夹并使用 npm cache clearrm -rf node_modulesnpm install 重新安装所有内容,但仍无法解决问题。

【问题讨论】:

    标签: module npm webpack webstorm npm-install


    【解决方案1】:

    您还应该在 node_modules 目录下有 d.ts 文件。试试看

    npm install --save-dev @types/redux-promise
    

    获取模块的类型信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-19
      • 2017-12-07
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 2019-07-01
      相关资源
      最近更新 更多