最佳答案
我正在学打字机。虽然我不认为这是相关的,但我正在使用 VSCode 为这个演示。
我有一个 package.json
里面有这些片段:
{
"devDependencies": {
"gulp": "^3.9.1",
"jspm": "^0.16.33",
"typescript": "^1.8.10"
},
"jspm": {
"moment": "npm:moment@^2.12.0"
}
}
然后我有一个类 main.js
,像这样:
import moment from 'moment';
export class Main {
}
My gulpfile.js
looks like this:
var gulp = require('gulp');
var typescript = require('gulp-tsb');
var compilerOptions = {
"rootDir": "src/",
"sourceMap": true,
"target": "es5",
"module": "amd",
"declaration": false,
"noImplicitAny": false,
"noResolve": true,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
};
var typescriptCompiler = typescript.create(compilerOptions);
gulp.task('build', function() {
return gulp.src('/src')
.pipe(typescriptCompiler())
.pipe(gulp.dest('/dest'));
});
When I run gulp build, I get the message: "../main.ts(1,25): Cannot file module 'moment'."
If I use import moment = require('moment');
then jspm will work and bring in the module when I run the application, but I'm still receiving the build error.
我也试过:
npm install typings -g
typings install moment --ambient --save
然而,问题并没有得到改善,反而变得更糟了。现在我得到了构建时的上述错误以及以下错误: "../typings/browser/ambient/moment/index.d.ts(9,21): Cannot find namespace 'moment'."
If I go to the file provided by typings and add at the bottom of the file:
declare module "moment" { export = moment; }
我可以得到第二个错误消失,但我仍然需要的需求语句,以获得在我的 main.ts
文件的工作时刻,我仍然得到第一个构建错误。
我需要创建我自己的 .d.ts
文件的时刻还是只是一些安装片段我错过了?