【问题标题】:pm ERR! missing script: build. I try to build one js file. I have npm library/npm 错误!缺少脚本:构建。我尝试构建一个 js 文件。我有 npm 库/
【发布时间】:2021-10-14 12:32:41
【问题描述】:

我的主要代码。我在 node_modules 文件夹中有“require('node-rsa')”。是否可以使用此代码创建一个文件?

a.js

var testFunct = function test(message) { 
    const NodeRSA = require('node-rsa');
    const key = new NodeRSA(); 
    var k = key.generateKeyPair(); 
    var p = k.exportKey('pkcs1'); 
    return p};
console.log(testFunct())

package.json

{
  "name": "pol",
  "version": "1.0.0",
  "description": "",
  "main": "a.js",
  "dependencies": {
    "node-rsa": "^1.1.1",
    "build": "webpack a.js b.js"
  },
  "devDependencies": {
    "webpack": "^5.58.2"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

webpack.config.js

module.exports = {
    entry: ['a.js'],
    output: {
      path: './build',
      filename: 'bundle.js'
  
    }
  }

【问题讨论】:

  • 您将build 放入dependencies 而不是scripts...

标签: javascript node.js webpack


【解决方案1】:

将此条目添加到 package.json 的 scripts 部分:

"build": "webpack"

这将在您运行构建操作时触发 webpack。

【讨论】:

  • 我试过了,它现在显示另一个错误。
  • 现在的错误是什么?
猜你喜欢
  • 2018-09-03
  • 2021-03-03
  • 2019-03-08
  • 2020-08-14
  • 2021-09-03
  • 2023-04-08
  • 2019-02-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多