Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node Lambda: Import of ts-node results in TypeError

I am new to node and writing serverside code so please bear with me. Currently, I am writing a node lambda using Typescript. In order to use it inside of my project I need the typescript modules as a dependency so I list them in my package.json file and they are installed with npm install. Next I run npm test and I receive this error log.

LT-2012011001:example-data-sync amohnacs$ npm test

> [email protected] test /Users/amohnacs/Developer/git/example-data-sync
> nyc ./node_modules/.bin/jasmine-ts ./spec/**/*.spec.ts


/Users/amohnacs/Developer/git/example-data-sync/node_modules/ts-node/src/index.ts:313
      throw new TypeError(
            ^
TypeError: Unable to require `.d.ts` file.
This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension and loader (attached before `ts-node`) available alongside     `/Users/amohnacs/Developer/git/example-data-sync/node_modules/any-promise/implementation.d.ts`.
at getOutput (/Users/amohnacs/Developer/git/example-data-sync/node_modules/ts-node/src/index.ts:313:17)
at /Users/amohnacs/Developer/git/example-data-sync/node_modules/ts-node/src/index.ts:334:18
at Object.compile (/Users/amohnacs/Developer/git/example-data-sync/node_modules/ts-node/src/index.ts:462:19)
at Object.m._compile (/Users/amohnacs/Developer/git/example-data-sync/node_modules/ts-node/src/index.ts:392:44)
at Module._extensions..js (module.js:550:10)
at Object.require.extensions.(anonymous function) [as .ts] (/Users/amohnacs/Developer/git/example-data-sync/node_modules/ts-node/src/index.ts:395:12)
at NYC._readTranspiledSource (/Users/amohnacs/Developer/git/example-data-sync/node_modules/nyc/index.js:150:26)
at NYC.addFile (/Users/amohnacs/Developer/git/example-data-sync/node_modules/nyc/index.js:134:21)
at /Users/amohnacs/Developer/git/example-data-sync/node_modules/nyc/index.js:166:11
at /Users/amohnacs/Developer/git/example-data-sync/node_modules/nyc/index.js:231:5
npm ERR! Test failed.  See above for more details.

Here is my package.json

{
  "name": "example-data-sync",
  "version": "1.0.0",
  "description": "An example project using the serverless framework for a lambda that subscribes to kinesis events.",
  "main": "index.js",
  "scripts": {
    "postinstall": "./node_modules/.bin/tsd install && ./node_modules/.bin/tsd link",
    "sls:init": "./node_modules/.bin/sls project init -c",
    "test": "./node_modules/.bin/nyc ./node_modules/.bin/jasmine-ts ./spec/**/*.spec.ts",
    "dp:dev:meta": "sls meta sync -s dev -r us-east-1",
    "dp:dev:cf": "sls resources deploy -s dev -r us-east-1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://gitlab.com/danteinc-sandbox/example-data-sync.git"
  },
  "keywords": [
    "kinesis",
    "event",
    "stream"
  ],
  "author": "John Gilbert <[email protected]> (danteinc.com)",
  "private": true,
  "license": "SEE LICENSE IN LICENSE.md",
  "bugs": {
    "url": "https://gitlab.com/danteinc-sandbox/example-data-sync/issues"
  },
  "homepage": "https://gitlab.com/danteinc-sandbox/example-data-sync#README",
  "devDependencies": {
    "aws-sdk": "^2.6.1",
    "jasmine-console-reporter": "^1.2.7",
    "jasmine-ts": "0.0.3",
    "nyc": "^8.1.0",
    "serverless": "^0.5.0",
    "serverless-meta-sync": "^0.1.0",
    "ts-node": "^1.3.0",
    "tsd": "^0.6.5",
    "typescript": "^1.8.10"
  },
  "dependencies": {
    "bluebird": "^3.3.5",
    "dante-commons-lambda": "^0.X.0",
    "debug": "^2.2.0",
    "highland": "^2.5.1",
    "lodash": "^3.10.1",
    "moment": "^2.12.0"
  },
  "nyc": {
    "lines": 95,
    "statements": 95,
    "functions": 95,
    "branches": 95,
    "include": [
      "src/**/*.ts"
    ],
    "exclude": [
      "spec/**/*.spec.ts",
      "typings"
    ],
    "extension": [
      ".ts"
    ],
    "require": [
      "ts-node/register"
    ],
    "reporter": [
      "json",
      "html",
      "text-summary"
    ],
    "cache": false,
    "check-coverage": true,
    "all": true
  }
}

It is telling me that my project in configured incorrectly but following the path it looks as through something is going wrong in ts-node. Is there something that I am missing or have incorrect in my configuration of the project or am I possibly using the incorrect version of ts-node or Typescript.

Thank you in advance.

like image 204
androidtitan Avatar asked Dec 03 '25 01:12

androidtitan


1 Answers

Add node_modules in the nyc.exclude section of your package.json.

"nyc": {
  "exclude": [
    "spec/**/*.spec.ts",
    "typings",
    "node_modules"
  ],
like image 80
rundef Avatar answered Dec 04 '25 16:12

rundef



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!