node.js - 找不到模块 Bootstrap

标签 node.js twitter-bootstrap npm gruntjs browserify

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

当我运行“grunt”时

我明白了:

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”,还有其他一些丢失的模块随后报告了我安装的内容。但是,使用 bootstrap,即使在安装并确保它存在于 node_modules 目录中之后,我仍然遇到此错误。

任何帮助将不胜感激。

I am new to grunt, npm, nodejs etc. I am just trying to setup a software.

已附加任务代码。

有两个 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': '_'
              }
            }
          }

最佳答案

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

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

重点是您导出 $ 而不是 jQuery

关于node.js - 找不到模块 Bootstrap ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20132860/

相关文章:

mysql - 如何使用nodejs将本地MySQL数据库部署到Heroku

node.js - npm 安装@types/.../node_modules/react

jquery - 如何清除 Bootstrap 验证成功(或失败)类和图标?

javascript - 如何定位 Bootstrap 弹出窗口?

react-native - 使用 npm install -g expo-cli 安装 react native expo 的问题

javascript - 如何在 React Outlook-Web-addin 中安全更新 Office-js-依赖项?

javascript - React - 还有另一种方法来处理更新的状态,而不是将所有函数硬编码在 setState 方法的回调部分中?

javascript - 无法访问nodejs中的数组值

mysql - Sequelize 查询比 Knex 慢很多

javascript - Bootstrap 警报在大屏幕上覆盖行时出现问题