te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How to run ts script with package.json? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to run ts script with package.json? - Stack Overflow

programmeradmin3浏览0评论

I try to run typescript files with just a package.json file. So a minimum setup for running typescript files.

I just have a singel file: index.ts:

console.clear();
console.log("nic to see you!!");

and package.json file:


{
  "name": "Todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


But if I try to do :

npm start, I will get this error:

Error: Cannot find module 'D:\Mijn Documents\UDEMY\TypeScript\Todo\index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A plete log of this run can be found in:
npm ERR!     C:\Users\User.USER-PC\AppData\Roaming\npm-cache\_logs\2019-12-24T11_22_12_024Z-debug.log
PS D:\Mijn Documents\UDEMY\TypeScript\Todo>

So my question is: what I have to change that it will pile?

Thank you

oke, I have it now like this:

packagege.json:

{
  "name": "Todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build":"tsc -p ./src", 
    "start": "npm run build -- -w"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ts-node": "^8.5.4",
    "typescript": "^3.7.4"
  }
}

And I installed typescript

and I do: npm start. I still get this error:

 npm run build -- -w


> [email protected] build D:\Mijn Documents\UDEMY\TypeScript\Todo
> tsc -p ./src "-w"

error TS5057: Cannot find a tsconfig.json file at the specified directory: './src'.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `tsc -p ./src "-w"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A plete log of this run can be found in:
npm ERR!     C:\Users\User.USER-PC\AppData\Roaming\npm-cache\_logs\2019-12-24T11_33_38_340Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `npm run build -- -w`
npm ERR! Exit status 1

oke, I have it now like this:

{
  "name": "Todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "tsc main.ts dist/",
    "start": "npm run build -- -w"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ts-node": "^8.5.4",
    "typescript": "^3.7.4"
  }
}

and if I do this: npm run. I see this output:


> [email protected] build D:\Mijn Documents\UDEMY\TypeScript\Todo
> tsc main.ts dist/ "-w"

[1:46:58 PM] Starting pilation in watch mode...

error TS6053: File 'dist/.ts' not found.

[1:46:59 PM] Found 1 error. Watching for file changes.

oke, I see now this:

> [email protected] build D:\Mijn Documents\UDEMY\TypeScript\Todo
> tsc -p ./ "-w"

[2:00:31 PM] Starting pilation in watch mode...

[2:00:34 PM] Found 0 errors. Watching for file changes.

But where I can see the results then? Will be nice to go to some port, like: localhost:4200 in the browser, but how to do that?

I try to run typescript files with just a package.json file. So a minimum setup for running typescript files.

I just have a singel file: index.ts:

console.clear();
console.log("nic to see you!!");

and package.json file:


{
  "name": "Todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


But if I try to do :

npm start, I will get this error:

Error: Cannot find module 'D:\Mijn Documents\UDEMY\TypeScript\Todo\index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A plete log of this run can be found in:
npm ERR!     C:\Users\User.USER-PC\AppData\Roaming\npm-cache\_logs\2019-12-24T11_22_12_024Z-debug.log
PS D:\Mijn Documents\UDEMY\TypeScript\Todo>

So my question is: what I have to change that it will pile?

Thank you

oke, I have it now like this:

packagege.json:

{
  "name": "Todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build":"tsc -p ./src", 
    "start": "npm run build -- -w"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ts-node": "^8.5.4",
    "typescript": "^3.7.4"
  }
}

And I installed typescript

and I do: npm start. I still get this error:

 npm run build -- -w


> [email protected] build D:\Mijn Documents\UDEMY\TypeScript\Todo
> tsc -p ./src "-w"

error TS5057: Cannot find a tsconfig.json file at the specified directory: './src'.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `tsc -p ./src "-w"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A plete log of this run can be found in:
npm ERR!     C:\Users\User.USER-PC\AppData\Roaming\npm-cache\_logs\2019-12-24T11_33_38_340Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `npm run build -- -w`
npm ERR! Exit status 1

oke, I have it now like this:

{
  "name": "Todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "tsc main.ts dist/",
    "start": "npm run build -- -w"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ts-node": "^8.5.4",
    "typescript": "^3.7.4"
  }
}

and if I do this: npm run. I see this output:


> [email protected] build D:\Mijn Documents\UDEMY\TypeScript\Todo
> tsc main.ts dist/ "-w"

[1:46:58 PM] Starting pilation in watch mode...

error TS6053: File 'dist/.ts' not found.

[1:46:59 PM] Found 1 error. Watching for file changes.

oke, I see now this:

> [email protected] build D:\Mijn Documents\UDEMY\TypeScript\Todo
> tsc -p ./ "-w"

[2:00:31 PM] Starting pilation in watch mode...

[2:00:34 PM] Found 0 errors. Watching for file changes.

But where I can see the results then? Will be nice to go to some port, like: localhost:4200 in the browser, but how to do that?

Share Improve this question edited Dec 24, 2019 at 13:05 asked Dec 24, 2019 at 11:23 user12479221user12479221 5
  • 1 Install Typescript and pile it first? – CertainPerformance Commented Dec 24, 2019 at 11:24
  • 1 Or use npmjs./package/ts-node. Or just rename the file to .js, as there are no types in there. – jonrsharpe Commented Dec 24, 2019 at 11:26
  • Does this answer your question? How to run typescript piler as a package.json script without grunt or gulp – C.OG Commented Dec 24, 2019 at 11:28
  • thank you. But that is not the problem. Because I can just run ANgular projects. I already have node.js installed – user12479221 Commented Dec 24, 2019 at 11:28
  • check typescript setup video youtube./… – Rahul Sharma Commented Dec 24, 2019 at 15:29
Add a ment  | 

2 Answers 2

Reset to default 11

Try typing in the terminal as follows:

ts-node ./src/index.ts

Or, try the following modifications to the "start" script:

"start": "ts-node ./src/index.ts"

Thank you all!!

the trick was this in the package.json:

"start": "tsc-watch --onsuccess \"node dist/index.js\""
发布评论

评论列表(0)

  1. 暂无评论