0
我试图让打字稿及lodash在我的应用程序工作,但是当我运行打字稿+ lodash - 找不到模块
tsc --module commonjs lodash-test.ts
我总是让
lodash-test.ts(2,20): error TS2307: Cannot find module 'lodash'.
这仍然产生lodash -test.js文件
"use strict";
//lodash test that will be injected in index.html
var _ = require("lodash");
console.log('This is your lodash ts file');
console.info(_.chunk(['a', 'b', 'c', 'd'], 2));
现在,当我在浏览器中运行我的index.html文件,我越来越
lodash-test.js:3 Uncaught ReferenceError: require is not defined
在文件的第3行。
的Index.html文件
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<script type="text/javascript" src="bower_components/lodash/dist/lodash.min.js"></script>
<script type="text/javascript" src="lodash-test.js"></script>
</head>
<body>
<h3>Hey</h3>
</body>
</html>
我有我的分型文件夹中的lodash类型定义。我怎样才能确保Typescript可以找到这个lodash/index.d.ts文件?另外我该如何解决“需求未定义”的错误?
这是我的文件结构:
感谢您的帮助
尝试导入'd.ts'类型文件与'///参考路径=“”/>'命令在您的TypeScript文件的顶部。因为现在'tsc'现在已经知道你有类型文件。所以它找不到它。 – Blackus
@Blackus我已将我的lodash-test.ts更改为http://imgur.com/n8Kp5pv,并生成了图像右侧的内容。我还删除了index.html中的