1

NPM ライブラリの構築を学んでいます。そのソースコードはHEREにあります。アプリケーション (ライブラリを使用する) が自分でインストールできるようにlodash、peerDependency として配置しました。

問題は、@a6kme/mathアプリケーションにライブラリ ( ) をインストールしているときにUnhandled Rejection (ReferenceError): lodash is not defined、ライブラリのインポートでエラーが発生することです。確認したところ、他のライブラリを介してアプリケーションによってlodashがインストールされています。(フォルダ内lodashに存在しnode_modulesます)

===コードリポジトリからのいくつかのファイル===

じぶんのpackage.json

{
  "name": "@a6kme/math",
  "version": "1.0.5",
  "description": "",
  "main": "dist/math.js",
  "scripts": {
    "test": "jest",
    "build": "webpack --mode=production",
    "prepare": "npm run test",
    "posttest": "npm run build"
  },
  "files": [
    "/dist"
  ],
  "repository": {
    "type": "git",
    "url": "https://github.com/a6kme/math.git"
  },
  "keywords": [
    "webpack",
    "webpack-library",
    "bundling",
    "library"
  ],
  "author": "a6kme",
  "license": "MIT",
  "devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/preset-env": "^7.4.3",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.5",
    "eslint": "^5.3.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-plugin-import": "^2.17.2",
    "eslint-plugin-prettier": "^3.0.1",
    "jest": "^24.7.1",
    "lodash": "^4.17.11",
    "prettier": "1.17.0",
    "webpack": "^4.30.0",
    "webpack-cli": "^3.3.0"
  },
  "peerDependencies": {
    "lodash": "*"
  }
}

じぶんのwebpack.config.js

const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'math.js',
    library: 'mathJs'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      }
    ]
  },
  externals: [/^lodash\/.+$/]
};

じぶんの.babelrc

{
  "presets": ["@babel/preset-env"]
}

コード リポジトリにgithub の問題を作成しました。どこを見ればいいのか教えてください。

4

1 に答える 1