1

我正在尝试使用@soil/dom通过 webpack 调用的 npm 包,只需执行以下操作:

import {h} from '@soil/dom'

但是在运行时webpack,我收到这些警告和错误:

WARNING in ./node_modules/@soil/dom/build/index.js 3:24-31
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ./src/index.ts

ERROR in ./node_modules/@soil/dom/build/index.js
Module not found: Error: Can't resolve './html/h' in '/home/daniel/Code/time-flies/node_modules/@soil/dom/build'
 @ ./node_modules/@soil/dom/build/index.js 7:8-70
 @ ./src/index.ts

我的package.json文件如下所示:

{
  "dependencies": {
    "@soil/dom": "0.6.0"
  },
  "devDependencies": {
    "typescript": "2.9.1",
    "ts-loader": "4.4.1",
    "webpack": "4.12.0",
    "webpack-cli": "3.0.3"
  }
}

我的webpack.config.js文件如下所示:

const path = require('path')

module.exports = {
    mode: 'production',
    entry: './src/index.ts',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    resolve: {
        extensions: ['.ts']
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: 'ts-loader',
                exclude: /node_modules/
            }
        ]
    }
}

@soil/dom侧面看,npm 包的目录结构如下所示:

@soil/
└── dom
    ├── build
    │   ├── html
    │   │   ├── h.js
    │   │   └── ...
    │   ├── index.js
    │   └── ...
    ├── package.json
    └── ...

package.json包含:

{
    "main": "build/index.js"
}

index.js文件包含(它是针对 UMD 模块系统编译的):

var h_1 = require("./html/h");
exports.h = h_1.h;

为什么此时 webpack 无法解析相对路径'./html/h'?这张照片中缺少什么?

4

0 回答 0