Skip to content

Instantly share code, notes, and snippets.

@dherges
Last active August 21, 2016 17:29
Show Gist options
  • Save dherges/701e5965dd5708529410ee47e4b0c798 to your computer and use it in GitHub Desktop.
Save dherges/701e5965dd5708529410ee47e4b0c798 to your computer and use it in GitHub Desktop.
foo-ts2307
.DS_Store
node_modules/
dist/

Why 'error TS2307: Cannot find module'?

Compile error

$ tsc -p tsconfig.json 
index.ts(3,26): error TS2307: Cannot find module 'halfred'.

Runtime everything fine

$ node dist/index.js
Resource {
  _links: {},
  _curiesMap: {},
  _curies: [],
  _resolvedCuriesMap: {},
  _embedded: {},
  _validation: [],
  foo: 'bar',
  _original: { foo: 'bar' } 
declare module halfred {
export function parse(object: any): Object;
export function enableValidation(flag: boolean): void;
export function disableValidatio (): void;
export class Resource {}
}
/// <reference path="./halfred.d.ts" />
import halfred = require('halfred');
let resource = halfred.parse({foo: "bar"});
console.log(resource);
{
"name": "foo-ts2307",
"version": "1.0.0",
"description": "TS2307: Cannot find module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"halfred": "^1.0.0"
}
}
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noEmitHelpers": true,
"noImplicitAny": true,
"declaration": true,
"outDir": "dist",
"types": []
},
"exclude": [
"node_modules",
"dist"
],
"files": [
"./index.ts"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment