首页 > 解决方案 > webpack 抱怨找不到模块

问题描述

@company\core我刚刚添加了一个名为我的反应应用程序的外部包。该外部包依赖于aws-sdk

@company\core用打字稿编写并构建/转译成 js。

在 npm i 之后,文件夹结构如下所示

\react-app\node_modules\aws-sdk
\react-app\node_modules\@company\core\node_modules\aws-sdk

但它失败了

import * as Core  from '@company/core';

错误内容如下:

Uncaught Error: Cannot find module 'aws-sdk'
    at webpackEmptyContext (:3000/static/js/main.chunk.js:11)
    at :3000/static/js/17.chunk.js:44252
    at :3000/static/js/17.chunk.js:44231
    at Object.<anonymous> (:3000/static/js/17.chunk.js:44239)
    at Object../node_modules/@company/core/lib/index.js (:3000/static/js/17.chunk.js:44438)
    at __webpack_require__ (:3000/static/js/bundle.js:787)
    at fn (:3000/static/js/bundle.js:150)
    at Module../src/utilities/amplifyInit.js (:3000/static/js/main.chunk.js:3118)
    at __webpack_require__ (:3000/static/js/bundle.js:787)
    at fn (:3000/static/js/bundle.js:150)
    at Module../src/App.js (:3000/static/js/main.chunk.js:121)
    at __webpack_require__ (:3000/static/js/bundle.js:787)
    at fn (:3000/static/js/bundle.js:150)
    at Module../src/index.js (:3000/static/js/main.chunk.js:2470)
    at __webpack_require__ (:3000/static/js/bundle.js:787)
    at fn (:3000/static/js/bundle.js:150)
    at Object.0 (:3000/static/js/main.chunk.js:3284)
    at __webpack_require__ (:3000/static/js/bundle.js:787)
    at checkDeferredModules (:3000/static/js/bundle.js:46)
    at Array.webpackJsonpCallback [as push] (:3000/static/js/bundle.js:33)
    at :3000/static/js/main.chunk.js:1

为什么 aws-sdk 是不可见的?任何想法?

标签: javascriptreactjstypescript

解决方案


推荐阅读