NodeJS (Server): ReferenceError: require is not defined when type: module

前端 未结 2 2008
既然无缘
既然无缘 2021-01-18 12:08

On Node 13.8 I\'m trying to use import / export.

EG: import {ChatClient, Message, MessageParser} from \'./chat-client/module.js\';

But when i d

2条回答
  •  长情又很酷
    2021-01-18 12:37

    As the documentation says:

    No require, exports, module.exports, __filename, __dirname
    These CommonJS variables are not available in ES modules.
    

    https://nodejs.org/api/esm.html#esm_no_require_exports_module_exports_filename_dirname

    You can't use both natively. If you want to do that use Babel to transpile your code.

提交回复
热议问题