在nodejs中找不到模块“filepath”

zpf6vheq  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(333)

这是我的文件夹结构。
/节点单元/

....
   ....

/src/

....
   index.ts
        export default app.listen(PORT, () => {
        console.log('Server is listening on port 3000')
    });
   ....

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "typeRoots": [
      "@types",
      "./node_modules/@types"
    ]
  },
  "include" : [
    "src/**/*.ts"
  ],
  "exclude" : [
    "node_modules"
  ]
}

/试验/

hello.ts
const chaai = require('chai')
      const httpChai = require('chai-http')
      const server = require('../src/index')

      chaai.use(httpChai)

      describe('registration API', ()=>{
      describe('GET /api/register', ()=>{
       it("It should throw error", (done)=>{
           chaai.request(server)
           .post('/api/register')
        //    @ts-ignore
           .end((err, response)=>{
               response.status.should.equal(400)
               done()
           })
       })
   }) 
})

package.json

"scripts": {
    "test": "mocha 'test/**/*.ts'"
  },

应用程序结构

root
   node_modules
   src
      modules
         module1
         module2
      index.ts
   tsconfig.json
   package.json

现在当我运行npm测试时,它说 Error: Cannot find module '../src/index' 我还尝试将测试文件夹移动到src文件夹中。但它不起作用。
在测试文件中,在 /test/hello.ts 如果我使用import,则表示不能在模块外使用import语句。
现在在测试文件中 /test/hello.ts ,我要求柴先生 const chaai = require('chai') 并将其储存在 chaai 变量但如果我把它储存在 chai 变量为 const chai = require('chai') ,然后typescript发出警告 Cannot redeclare block-scoped variable 'chai'.ts(2451) index.d.ts(1968, 15): 'chai' was also declared here. 我如何解决这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题