SyntaxError: Unexpected token export解决

在config中添加app时使用了export default,但是报错SyntaxError: Unexpected token export,查阅资料后发现关于 export 和export default的相关资料:
export与export default均可用于导出常量、函数、文件、模块等
在一个文件或模块中,export、import可以有多个,export default仅有一个
通过export方式导出,在导入时要加{ },export default则不需要
export能直接导出变量表达式,export default不行。
因此我猜测文件中已经存在export default了,所以把app写在了module.exports中就不报错了

export default中的default是一种特殊的系统变量,export default的含义是把此命令后面的变量赋值给default这个特殊的系统变量,并把它导出到其他模块中使用

关于exports和module.exports:
在一个node执行一个文件时,会给这个文件内生成一个 exports和module对象,而module有一个exports属性。
exports = module.exports = {};

参考:这里是超链接
https://segmentfault.com/a/1190000019582600

猜你喜欢

转载自blog.csdn.net/weixin_44051236/article/details/106249010