NPM链接尝试在src文件夹而不是dist文件夹中查找模块

时间:2019-11-13 09:20:17

标签: node.js angular npm

我已经与Angular CLI Builder一起工作,创建了一个自定义构建器,以扩展angular.json中的资产配置,以防库拥有它自己的资产。我使用nrwl来管理工作区。

我创建了一个角度cli生成器库并运行npm link。它创建一个dist文件夹。在使用该库的项目中,我运行npm link packagename,但是当我运行npm run build时,它显示为Can not find module X in path ../src/command。我不明白为什么它查看的是src文件夹而不是dist文件夹?

我的package.json文件

{
  "name": "packagename",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "builders": "builders.json",
  "scripts": {
    "build": "tsc"
  },
  "devDependencies": {
    "@angular-devkit/architect": "^0.803.3",
    "prettier": "1.18.2",
    "ts-jest": "24.0.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "^3.4.5"
  }
}

和tsconfig.json文件

{
  "compilerOptions": {
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "outDir": "dist",
    "rootDir": "src",
    "module": "commonjs",
    "target": "es5",
    "types": ["node"],
    "lib": ["es2015", "es2017"]
  },
  "include": ["src/**/*.ts"],
  "exclude": ["example/**/*.ts"]
}

您能帮我吗?

1 个答案:

答案 0 :(得分:0)

一切正常。当我有一个包时,我需要指向angular.json来使用我的构建器。问题是当它看着builders.json

<div class="modal fade" id="DialogPipe" tabindex="-1" role="dialog" aria-labelledby="DialogPipeLabel" aria-hidden="true">
  <div class="modal-backdrop fade in"></div>
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="DialogPipeLabel">Edit pipe</h4>
      </div>
      <div class="modal-body">
        <form id="frm_DialogPipe">
          <div class="table-responsive">
            <table class="table table-striped table-condensed">
              <colgroup>
                <col class="col-md-3" />
                <col class="col-md-9" />
              </colgroup>
              <tbody>
                <tr id="row_pipe.bandwidth">
                  <td>
                    <div class="control-label" id="control_label_pipe.bandwidth">
                      <a id="help_for_pipe.bandwidth" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a>
                      <b>Bandwidth</b>
                    </div>
                  </td>
                  <td>
                    <input type="text" class="form-control " size="50" id="pipe.bandwidth">
                  </td>
                </tr>
                <tr id="row_pipe.bandwidthMetric">
                  <td>
                    <div class="control-label" id="control_label_pipe.bandwidthMetric">
                      <i class="fa fa-info-circle text-muted"></i>
                      <b>Bandwidth Metric</b>
                    </div>
                  </td>
                  <td>
                    <select id="pipe.bandwidthMetric" class="selectpicker" data-width="334px"></select>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
        <button type="button" class="btn btn-primary" id="btn_DialogPipe_save">Save <i id="btn_DialogPipe_save_progress" class=""></i></button>
      </div>
    </div>
  </div>
</div>

这就是为什么它指向{ "builders": { "browser": { "implementation": "./dist/browser", --it was "./src/browser" "schema": "../../../node_modules/@angular-devkit/build-angular/src/browser/schema.json", "description": "Add assets and runs @angular-devkit/build-angular:browser" } } } 文件夹而不是src文件夹的原因。