【问题标题】:serverless-webpack can't resolve moduleserverless-webpack 无法解析模块
【发布时间】:2018-10-13 08:55:27
【问题描述】:

从 serverless-webpack 得到这个错误:

ERROR in ../db/actions/index.js
Module not found: Error: Can't resolve 'amazon-dax-client' in '/var/task/db/actions'
 @ ../db/actions/index.js 2:24-52
 @ ../db/db.js
 @ ./crop.js

我的 webpack.config.js 文件包含:

const slsw = require('serverless-webpack')

module.exports = {
    entry: slsw.lib.entries,
    target: 'node',
    externals: {
        sharp: 'commonjs sharp',
    },
    // Run babel on all .js files and skip those in node_modules
    module: {
        rules: [{
            test: /\.js$/,
            loader: 'babel-loader',
            include: __dirname,
            exclude: /node_modules/,
        }]
    }
}

amazon-dax-client 模块存在于 node_modules 中。

我已回滚到适用于我的最新版本的 webpack 和 serverless-webpack:

"serverless-webpack": "4.3.0",
"webpack": "3.11.0"

关于如何解决或获得额外的日志输出以追踪问题的任何想法?

【问题讨论】:

    标签: webpack serverless serverless-webpack-plugin


    【解决方案1】:

    或者,您可以考虑使用node-prune 从 node_modules (.md, .ts, ...) 中删除不必要的文件。它不会像 webpack 那样有效,但它不那么复杂,而且绝对不会出错。对于某些项目来说它已经足够好了。

    【讨论】:

      【解决方案2】:

      您可以尝试删除 /node_modules/ 排除项吗?如果将其删除,我想它可以进入该文件夹并执行您需要的操作。由于 amazon-dax-client 位于该文件夹中,并且您告诉 webpack 忽略 node_modules 文件夹,因此它将无法访问它。让我知道这是否有帮助。

      【讨论】:

      • 我注释掉了那行,得到了同样的结果。
      • 你能和我分享你的文件结构并指出你的入口点吗?我对可能发生的事情有一个想法。
      【解决方案3】:

      我不再收到该错误,但我无法具体说明是什么修复了它。删除package-lock.jsonnode_modules 似乎是催化剂。

      【讨论】:

        猜你喜欢
        • 2021-11-04
        • 2021-07-21
        • 2021-10-27
        • 2016-11-04
        • 2021-05-21
        • 2017-09-21
        • 2019-11-15
        • 1970-01-01
        相关资源
        最近更新 更多