gpt4 book ai didi

javascript - 安装新的 Angular 模块时出现 nomod 错误

转载 作者:太空宇宙 更新时间:2023-11-04 16:12:08 27 4
gpt4 key购买 nike

当我尝试将 braintree-Angular 包含到我的 gulp-Angular 项目中时,出现以下错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module notecards due to:
Error: [$injector:modulerr] Failed to instantiate module braintree-angular due to:
Error: [$injector:nomod] Module 'braintree-angular' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

我经常遇到在 gulp-Angular 项目中加载新安装的模块时遇到的问题,我相信这是由于普遍缺乏对 gulp 工作原理的理解。该项目的 gulp 部分是由一位同事设置的。如果有人能解释为什么我继续看到这样的问题,我将不胜感激!

我已经检查了以下内容:

  • 该模块已正确安装在我的 /node_modules 文件夹中。
  • 该模块在我的 package.json 中正确显示。
  • 整个文件夹都是可读的(我之前遇到过导致此问题的文件权限问题。但这里不是这种情况。)
  • gulp加载 Braintree-Angular 文件。

gulp/server.js

'use strict';

var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
//var babel = require('gulp-babel');

var browserSync = require('browser-sync');
var browserSyncSpa = require('browser-sync-spa');

var util = require('util');

var proxyMiddleware = require('http-proxy-middleware');

function browserSyncInit(baseDir, browser) {
browser = browser === undefined ? 'default' : browser;

var routes = null;
if (baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) {
routes = {
'/bower_components': 'bower_components'
};
}

var server = {
baseDir: baseDir,
routes : routes
};

/*
* You can add a proxy to your backend by uncommenting the line below.
* You just have to configure a context which will we redirected and the target url.
* Example: $http.get('/users') requests will be automatically proxified.
*
* For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.9.0/README.md
*/
// server.middleware = proxyMiddleware('/users', {target: 'http://jsonplaceholder.typicode.com', changeOrigin: true});

browserSync.instance = browserSync.init({
startPath: '/',
server : server,
browser: browser,
host: '192.168.0.20',
https: false,
port : parseInt(process.env.GULP_PORT) || 8684
});
}

browserSync.use(browserSyncSpa({
selector: '[ng-app]'// Only needed for angular apps
}));

gulp.task('serve', ['watch'], function () {
browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]);
});

gulp.task('serve:dist', ['build'], function () {
browserSyncInit(conf.paths.dist);
});

gulp.task('serve:e2e', ['inject'], function () {
browserSyncInit([conf.paths.tmp + '/serve', conf.paths.src], []);
});

gulp.task('serve:e2e-dist', ['build'], function () {
browserSyncInit(conf.paths.dist, []);
});

var gulp = require('gulp');
var webserver = require('gulp-webserver');

gulp.task('webserver', function() {
gulp.src('src')
.pipe(webserver({
host: '0.0.0.0',
livereload: true,
directoryListing: true,
open: true
}));
});

gulpfile.js

/**
* Welcome to your gulpfile!
* The gulp tasks are splitted in several files in the gulp directory
* because putting all here was really too long
*/

'use strict';

var gulp = require('gulp');
var wrench = require('wrench');

/**
* This will load all js or coffee files in the gulp directory
* in order to load all gulp tasks
*/
wrench.readdirSyncRecursive('./gulp').filter(function (file) {
return (/\.(js|coffee)$/i).test(file);
}).map(function (file) {
require('./gulp/' + file);
});


/**
* Default task clean temporaries directories and launch the
* main optimization build task
*/
gulp.task('default', ['clean'], function () {
gulp.start('build');
});

package.json

{
"name": "healthbydna",
"version": "0.0.0",
"dependencies": {
"angular-chart.js": "^1.0.3",
"babel": "^6.5.2",
"braintree-angular": "^1.5.0",
"gulp-babel": "^6.1.2",
"gulp-extend": "^0.2.0",
"gulp-if": "^2.0.0",
"gulp-ng-constant": "^1.1.0",
"jotted": "^1.5.1",
"lazypipe": "^1.0.1"
},
"scripts": {
"test": "gulp test"
},
"devDependencies": {
"babel-core": "^6.21.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-es2016": "^6.16.0",
"browser-sync": "~2.9.11",
"browser-sync-spa": "~1.0.3",
"chalk": "~1.1.1",
"del": "~2.0.2",
"eslint-plugin-angular": "~0.12.0",
"estraverse": "~4.1.0",
"gulp": "^3.9.1",
"gulp-angular-filesort": "~1.1.1",
"gulp-angular-templatecache": "~1.8.0",
"gulp-autoprefixer": "~3.0.2",
"gulp-eslint": "~1.0.0",
"gulp-filter": "~3.0.1",
"gulp-flatten": "~0.2.0",
"gulp-inject": "~3.0.0",
"gulp-load-plugins": "~0.10.0",
"gulp-minify-css": "~1.2.1",
"gulp-minify-html": "~1.0.4",
"gulp-ng-annotate": "~1.1.0",
"gulp-protractor": "~1.0.0",
"gulp-rename": "~1.2.2",
"gulp-replace": "~0.5.4",
"gulp-rev": "~6.0.1",
"gulp-rev-replace": "~0.4.2",
"gulp-sass": "~2.0.4",
"gulp-size": "~2.0.0",
"gulp-sourcemaps": "~1.6.0",
"gulp-uglify": "~1.4.1",
"gulp-useref": "~1.3.0",
"gulp-util": "~3.0.6",
"gulp-webserver": "^0.9.1",
"http-proxy-middleware": "~0.9.0",
"karma": "~0.13.10",
"karma-angular-filesort": "~1.0.0",
"karma-coverage": "~0.5.2",
"karma-jasmine": "~0.3.6",
"karma-ng-html2js-preprocessor": "~0.2.0",
"karma-phantomjs-launcher": "~0.2.1",
"lodash": "~3.10.1",
"main-bower-files": "~2.9.0",
"phantomjs": "~1.9.18",
"uglify-save-license": "~0.4.1",
"wiredep": "~2.2.2",
"wrench": "~1.5.8"
},
"engines": {
"node": ">=0.10.0"
}
}

最佳答案

Gulp 只是一个(非常强大的)任务运行程序,简单明了。它可以完成您自己可以做但您没有时间做的事情;)

节点模块与 Angular 模块不同。 Node 模块具有广泛的范围,用于在 Node.js 平台中运行通用代码。也就是说,Javascript 在典型的网络浏览器设置之外运行。例如桌面应用程序、贷款计算器、网络服务器、聊天程序等。

但是,许多 Node 模块专门用于 Angular,并且有 Bower 对应模块。 Bower 包确实可以直接包含在您的网页中:

<script src="./bower_components/path/to/script.js" type="text/javascript"></script>

您可能会问,为什么 Web 模块同时存在 Node 模块和 Bower 包?这是因为像 Browserify 这样的捆绑程序和 Webpack,让您可以在网页中实际使用 Node 模块。您的项目似乎没有为捆绑程序设置。

您想要为您的模块获取已编译的 JS(最好通过修改 gulpfile 以从节点模块的文件夹编译和/或连接正确的 JS 文件)或使用 Bower 下载已编译的 JS,并修改 gulp文件以将其包含到串联过程中。

有多个文件构成了您的项目的 Gulp 进程。在这些文件之一中查找“构建”任务。它应该包括有关如何构建 vendor JS 文件的详细信息。您想要修改它,以便它包含 braintree-Angular 的 JS 文件的路径(如果存在)

关于javascript - 安装新的 Angular 模块时出现 nomod 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41384368/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com