社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  docker

npx ts lint在Docker中运行时找不到模块“typescript”

Mnebuerquo • 5 年前 • 506 次点击  

我正在为api项目的node/typescript设置一个停靠的开发环境。目标是在Docker中运行所有的东西,而不是在主机上安装任何节点、NPM或模块。这是为了将node和所有模块的所有版本与其他项目隔离开来。

/节点

docker run \
    -it \
    -p "8080:80" \
    --rm \
    -w "/app" \
    -v "$(pwd):/app" \
    "node:10" "$@"

/净现值

#!/bin/sh
./node npm $@

/净现值

#!/bin/sh
./node npx $@

./package.json包

{
  "name": "testapi",
  "version": "0.0.1",
  "description": "a hello world api",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "npx ts-node src/app.ts",
    "lint": "npx ts-lint --project src $@"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^6.2.0",
    "fastify": "^1.13.2",
    "ts-node": "^7.0.1"
  },
  "devDependencies": {
    "@types/node": "^10.12.15",
    "ts-lint": "^4.5.1",
    "typescript": "^3.2.2"
  }
}

[编辑]

我用 ./npm install 建立我的节点模块。节点模块位于共享卷中,因此在移除容器后,它将在主机上保持。这样我就不需要Dockerfile来构建图像。

[/编辑]

当我运行lint命令时,出现以下错误:

testapi$ ./npx ts-lint -i
10: Pulling from node
Digest: sha256:5af431757f84bf7878ff72447eb993fc37afcd975874fff13278157bf83661e6
Status: Image is up to date for docker-remote.registry.kroger.com/node:10
npx: installed 32 in 2.883s
Cannot find module 'typescript'

我认为这与模块分辨率有关,但我不确定。我看到人们在全球安装typescript,但这意味着我必须使用dockerfile而不是stock节点映像。我不介意为dev使用Dockerfile,但我认为应该有一种方法可以在不这样做的情况下使这个工作。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46537
 
506 次点击  
文章 [ 1 ]  |  最新文章 5 年前