【问题标题】:Can't find module Bootstrap找不到模块引导程序
【发布时间】:2013-12-06 14:59:54
【问题描述】:

我正在运行“grunt”的目录有 node_module 文件夹,其中包含所有模块,包括:Bootstrap、Browserify 和其他。

当我运行“咕噜”时

我明白了:

Running "jshint:files" (jshint) task
>> 12 files lint free.

Running "copy:build" (copy) task
Created 1 directories, copied 17 files

Running "concat:vendorcss" (concat) task
File "build-css/vendor.less" created.

Running "less:libremap" (less) task
File build/css/libremap.css created.

Running "jst:compile" (jst) task
File "build-jst/templates.js" created.

Running "browserify:vendor" (browserify) task
>> Bundled build/vendor/vendor.js

Running "browserify:libremap" (browserify) task
Warning: Cannot find module 'bootstrap' Use --force to continue.

它在 browserify 处停止并说在这种情况之前找不到模块'bootstrap',它说在重新启动“grunt”后没有我用“npm install jquery”安装的“jquery”,还有一些其他缺失的模块随后报告了我安装的内容。但是使用引导程序,即使在安装并确保它存在于 node_modules 目录之后,我仍然有这个错误。

任何帮助将不胜感激。

我是 grunt、npm、nodejs 等的新手。我只是想设置一个 软件。

已附加任务代码。

有两个 Browserify 任务,我假设从上面的输出中第一个成功完成?

browserify: {
 vendor: {
        src: [],
        dest: 'build/vendor/vendor.js',
        options: {
          shim: {
            jquery: {
              path: 'bower_components/jquery/jquery.min.js',
              exports: '$'
            },
            bootstrap: {
              path: 'bower_components/bootstrap/dist/js/bootstrap.min.js',
              exports: 'bootstrap',
              depends: {
                'jquery': 'jQuery'
              }
            },
            leaflet: {
              path: 'vendor/leaflet/leaflet.js',
              exports: 'L'
            },
            'leaflet-markercluster': {
              path: 'vendor/leaflet.markercluster/leaflet.markercluster.js',
              exports: 'L',
              depends: {
                'leaflet': 'L'
              }
            }
          }
        }
      },

// browserify libremap.js -> bundle.js
      libremap: {
        dest: 'build/js/libremap.js',
        src: [ 'src/js/libremap.js' ],
        options: {
          debug: grunt.option('debug'),
          external: ['jquery', 'bootstrap', 'leaflet', 'leaflet-markercluster'],
          shim: {
            templates: {
              path: 'build-jst/templates.js',
              exports: 'JST',
              depends: {
                'underscore': '_'
              }
            }
          }

【问题讨论】:

  • 请在 gruntfile.js 中显示您的 browserify 任务
  • @Shrike 请检查添加的代码。
  • @Shrike 知道路径问题吗?我刚刚删除了 bower_componets 和 node_components 并重新安装。然后我注意到, bower_components 具有所需的组件。当我运行脚本时,它告诉我 jquery is module is not found,同时,它在 bower_components。如果我进一步安装它,它将被添加到 node_components 并且当 grunt 运行时,它不会再次要求它,现在,传单等等,但它以某种方式卡在引导程序中。

标签: node.js twitter-bootstrap npm gruntjs browserify


【解决方案1】:

试试这个,应该会有帮助:

`bootstrap: {
          path: 'bower_components/bootstrap/dist/js/bootstrap.min.js',
          exports: 'bootstrap',
          depends: {
            'jquery': '$'
          }
        },`

关键是你导出$而不是jQuery

【讨论】:

    【解决方案2】:

    试试:

    npm -g install bower
    bower install bootstrap
    

    【讨论】:

    • root@student-mapper:/usr/local/src/libremap-webui# bower install bootstrap --allow-root bower bootstrap#* cached git://github.com/twbs/bootstrap.git#3.0.2 bower bootstrap#* validate 3.0.2 against git://github.com/twbs/bootstrap.git#* bower jquery#>= 1.9.0 cached git://github.com/components/jquery.git#2.0.3 bower jquery#>= 1.9.0 validate 2.0.3 against git://github.com/components/jquery.git#>= 1.9.0 我按照你的建议做了,但没有解决问题:(
    • 试试这个:npm install bootstrap-browserify 然后再次运行
    • bower_components 目录有''bootstrap font-awesome jquery leaflet'' 我现在试过了,结果还是一样。
    • 我认为这是来自 grunt 脚本的路径问题? browserify 的第一个脚本是成功的,并且写入了引导程序的路径,但另一个没有?我只能看到带有组件名称的“外部”。或者这意味着不同?
    • 你能发布 Gruntfile(或其中的一部分)吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    相关资源
    最近更新 更多