【问题标题】:SyntaxError: Cannot use import statement outside a module when setting up socket.io in adonisjsSyntaxError:在adonisjs中设置socket.io时无法在模块外使用import语句
【发布时间】:2021-12-25 22:18:55
【问题描述】:

我正在关注socketio with adonisjs 以便能够实现 Web 套接字,但我明白了 这个错误

[ info ]  building project...
[ info ]  starting http server...

SyntaxError: Cannot use import statement outside a module

at /home/../providers/AppProvider.ts(anonymous):18
13    }
14  
15    public async ready () {
16      // App is ready
17      if (this.app.environment === 'web') {
18        await import('../start/socket')
19  
20      }
21    }
22  
23    public async shutdown () {

[ encore ] Running webpack-dev-server ...
[ warn ]  Underlying HTTP server died with "0 code"

当我尝试将 "type": "module", 添加到 package.json 的 solution 时,我得到了其他错误

我该如何解决这个问题?

【问题讨论】:

  • 你能分享更多代码吗?
  • 你想看看 start/socket.js 里有什么
  • 在哪里导入socket io模块?
  • app/Services/Ws.ts 就像this says。我尝试添加代码,但对于帖子来说太多了

标签: javascript import async-await socket.io adonis.js


【解决方案1】:

原来我使用的是start/socket.js 而不是start/socket.ts

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 2020-08-25
    • 2022-11-02
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 2023-01-31
    • 2020-02-11
    相关资源
    最近更新 更多