我正在使用 Bootstrap v4.0.0-alpha.3 和 Gulp.js v.3.9.1 开发一个Web应用程序,用于 Webstorm 2016.2中的任务自动化 macOS Sierra版本10.12 操作系统上的.3 IDE ,并为我的服务器使用节点和 express 。并且一直在Pluralsight关注John Papa的Gulp.js课程作为创建我的gulpfile的参考。
在终端上运行gulp命令运行任务时,我在终端中收到以下错误:
var port = process.env.PORT || config.defaultPort;
^
TypeError: Cannot read property 'defaultPort' of undefined
at Object.<anonymous> (/projects/TEST/bbusy/gulpfile.js:42:38)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Liftoff.handleArguments (/usr/local/lib/node_modules/gulp/bin/gulp.js:116:3)
at Liftoff.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:198:16)
at module.exports (/usr/local/lib/node_modules/gulp/node_modules/flagged-respawn/index.js:17:3)
error: Cannot read property of undefined
app.set('port', port) 'TypeError: undefined is not a function'. Beginner, need ideas
我试图通过在 Webstorm首选项中启用Node.js核心和Node.js全局来解决Webstorm中的类型错误。图书馆| JavaScript - 正如通过一些进一步的研究,这个建议突然出现了语法错误和类型错误。这还没有解决错误。
我还尝试了以下教程https://www.typescriptlang.org/docs/handbook/gulp.html,并创建了一个未解决错误的tsconfig.json
文件。
我重新检查了gulp.config.js
,gulpfile.js
和app.js
服务器文件中的相关代码,以确保没有错误。
Gulpfile.js:
'use strict';
var gulp = require('gulp');
var args = require('yargs').argv;
var browserSync = require('browser-sync');
var config = require('./gulp.config')();
var del = require('del');
var jshint = require('jshint');
var path = require('path');
var _ = require('lodash');
var $ = require('gulp-load-plugins')({lazy: true});
var port = process.env.PORT || config.defaultPort;
gulp.config.js:
module.exports = function() {
var client = './src/client/';
var clientApp = client + 'app/';
var report = './report/';
var root = './';
var server = './src/server/';
var temp = './.tmp/';
var wiredep = require('wiredep');
var bowerFiles = wiredep({devDependencies: true})['js'];
/**
* Node settings
*/
defaultPort: 7203,
nodeServer: './src/server/app.js'
};
App.js:
'use strict';
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var compress = require('compression');
var cors = require('cors');
var errorHandler = require('./utils/errorHandler.js')();
var favicon = require('serve-favicon');
var logger = require('morgan');
var port = process.env.PORT || 7203;
var routes;
var environment = process.env.NODE_ENV;
我想知道错误的来源和错过的内容?
答案 0 :(得分:0)
var config = require('./gulp.config')();
我尝试删除第二个()
var config = require('./gulp.config');