Typescript 为什么nodemon对我的src/文件夹中的更改没有反应?

Typescript 为什么nodemon对我的src/文件夹中的更改没有反应?,typescript,next.js,nodemon,Typescript,Next.js,Nodemon,当mysrc/文件夹的子目录中的文件发生更改时,nodemon不会对其更改做出反应,但当项目中的其他文件发生更改时,它会做出反应 package.json: "dev": "nodemon src/server.ts", "extends": "./tsconfig.json", "compilerOptions": { "module": "commonjs", "target": "es2017", "noEmit"

当my
src/
文件夹的子目录中的文件发生更改时,
nodemon
不会对其更改做出反应,但当项目中的其他文件发生更改时,它会做出反应

package.json

    "dev": "nodemon src/server.ts",
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2017",
        "noEmit": false,
        "outDir": "build/"
    },
    "include": ["src/server.ts"]
}
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "jsx": "preserve",
        "lib": ["dom", "es2017"],
        "baseUrl": ".",
        "moduleResolution": "node",
        "strict": true,
        "allowJs": true,
        "noEmit": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "isolatedModules": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "sourceMap": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true
    },
    "exclude": ["dist", ".next", "out", "next.config.js"],
    ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}
    "watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/**/*.ts", "src/**/*.tsx"],
    "exec": "ts-node --project tsconfig.server.json",
    "ext": "js json ts tsx"
}
nodemon.json
: *

ts.config.server.json

    "dev": "nodemon src/server.ts",
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2017",
        "noEmit": false,
        "outDir": "build/"
    },
    "include": ["src/server.ts"]
}
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "jsx": "preserve",
        "lib": ["dom", "es2017"],
        "baseUrl": ".",
        "moduleResolution": "node",
        "strict": true,
        "allowJs": true,
        "noEmit": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "isolatedModules": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "sourceMap": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true
    },
    "exclude": ["dist", ".next", "out", "next.config.js"],
    ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}
    "watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/**/*.ts", "src/**/*.tsx"],
    "exec": "ts-node --project tsconfig.server.json",
    "ext": "js json ts tsx"
}
ts.config.json

    "dev": "nodemon src/server.ts",
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2017",
        "noEmit": false,
        "outDir": "build/"
    },
    "include": ["src/server.ts"]
}
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "jsx": "preserve",
        "lib": ["dom", "es2017"],
        "baseUrl": ".",
        "moduleResolution": "node",
        "strict": true,
        "allowJs": true,
        "noEmit": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "isolatedModules": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "sourceMap": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true
    },
    "exclude": ["dist", ".next", "out", "next.config.js"],
    ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}
    "watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/**/*.ts", "src/**/*.tsx"],
    "exec": "ts-node --project tsconfig.server.json",
    "ext": "js json ts tsx"
}

您能显示server.ts文件吗? 您是否更改了server.ts的所有导入路径

我用的是nodemon和gulp,效果很好

gulp.task('serve', function (done) {
  nodemon({
    script: 'server/server.js'
  , ext: 'js html'
  , env: { 'NODE_ENV': 'development' }
  , done: done
  })
})

在nodemon.json中,尝试更改以下内容:

"watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/server.ts"],
为此:

"watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/**/*.ts"],

@保罗的回答似乎对
.ts
文件起到了作用! 为
.tsx
添加一个,但不起作用

最后的解决方案是添加一个
ext
字段,其中包含
json-ts-tsx

Final
nodemon.json

    "dev": "nodemon src/server.ts",
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2017",
        "noEmit": false,
        "outDir": "build/"
    },
    "include": ["src/server.ts"]
}
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "jsx": "preserve",
        "lib": ["dom", "es2017"],
        "baseUrl": ".",
        "moduleResolution": "node",
        "strict": true,
        "allowJs": true,
        "noEmit": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "isolatedModules": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "sourceMap": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true
    },
    "exclude": ["dist", ".next", "out", "next.config.js"],
    ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}
    "watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/**/*.ts", "src/**/*.tsx"],
    "exec": "ts-node --project tsconfig.server.json",
    "ext": "js json ts tsx"
}

不要在标题中添加标签,它应该读作一个句子。如果你可以将所有内容都作为文本而不是屏幕截图发布,例如文件夹结构可以很容易地从
命令的输出中复制粘贴。
当src/的子目录中的文件发生更改时,nodemon不会做出反应。
这一点不太清楚,你能把你的问题说得更具体一点吗?编辑了你文章的格式。谢谢@ruohola,我欠你一杯啤酒