【问题标题】:unable to import modules in node type using typescript无法使用打字稿导入节点类型的模块
【发布时间】:2016-04-12 20:45:03
【问题描述】:

我正在尝试使用带有 gulp 的 typescript 编写节点应用程序。我在其中编写 server.ts 文件打字稿为

import express from 'express';
import mongoose from 'mongoose';


let app=express();
app.set('port', process.env.PORT || 3000); // Set port to 3000 or the provided PORT variable


/**
 * Start app
 */
app.listen(app.get('port'), function() {
  console.log(`App listening on port ${app.get('port')}!`);
});

我已经使用 gulp 编译并放置在我将运行我的应用程序的 src 文件夹中

这是我的 gulpfile 代码:

var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var tsc = require('gulp-typescript');
var config = require('./gulp.config')();
var tsProject = tsc.createProject('tsconfig.json');



gulp.task('compile', function() {
  var sourceTsFiles = [
        config.allTs,
        config.typeings,
    ];
    var tsResult = gulp
        .src(sourceTsFiles)
        .pipe(sourcemaps.init())
        .pipe(tsc(tsProject));

    return tsResult.js
        .pipe(sourcemaps.write('./map'))
        .pipe(gulp.dest(config.tsOutPutPath));
});


gulp.task('default', function() {
  // place code for your default task here
});

这是我的 gulp.config 文件

module.exports = function () {
    var config = {
        allTs:'./server.ts',
        typeings:'./typings/**/*.ts',
        tsOutPutPath:'./src'
    };
    return config;
}

当我运行我的 gulp 任务时,我收到错误 找不到模块

我想知道为什么会出现这个错误,如果我做错了什么请纠正我。

【问题讨论】:

    标签: node.js typescript npm


    【解决方案1】:

    我犯了一个愚蠢的错误,我没有为这些模块安装打字。 安装所有类型的所有模块及其依赖项,它的 stat 工作正常。

    【讨论】:

    • 您能详细说明您的解决方案吗? :)
    猜你喜欢
    • 2022-01-14
    • 1970-01-01
    • 2019-11-12
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 2017-02-21
    • 2018-07-30
    相关资源
    最近更新 更多