Node --experimental-modules - Error: Cannot find module

后端 未结 3 1364
忘了有多久
忘了有多久 2021-02-02 07:20

I am getting an error when trying to import a local file, though no problem when using npm packages.

server.js

import express from \'express\'
import n         


        
3条回答
  •  爱一瞬间的悲伤
    2021-02-02 08:02

    I'm answering my own question if anybody else has this problem.

    It turns out in experimental mode you need to define the full path with extension. So I am trying to import index.js thinking it will know.

    To fix it:

    import express from 'express'
    import next from 'next'
    import api from './src/server/api/index.js'
    

提交回复
热议问题