zoukankan      html  css  js  c++  java
  • export报错SyntaxError: Unexpected token export

    const defaultFiles = [
    ]
    export default defaultFiles
    
    // 使用
    const defaultFiles  = require('./src/utils/defaultFiles ')
    
    //编译时报错:SyntaxError: Unexpected token export 。。。
    //说明此模块规范是CommonJS,需要
    //使用CommonJS
    module.exports = {
      defaultFiles 
    }

      

    根本原因

    Node和浏览器端所支持的模块规范不同。

    条目Node浏览器
    模块规范 CommonJS ES6
    导出 * modules.exports; exports export; export default
    引入 require import;require
    1. 关于exports和module.exports
    • 在一个node执行一个文件时,会给这个文件内生成一个 exports和module对象,
      而module有一个exports属性。
    • exports = module.exports = {};
    2. 关于 export 和export default
    • export与export default均可用于导出常量、函数、文件、模块等
    • 在一个文件或模块中,export、import可以有多个,export default仅有一个
    • 通过export方式导出,在导入时要加{ },export default则不需要
    • export能直接导出变量表达式,export default不行。

    参考来源:https://blog.csdn.net/binshaono_1/article/details/92977957

  • 相关阅读:
    一分钟 解决Tomcat端口 占用问题
    Java 自定义注解
    Java 解析自定义XML文件
    Junit(手动/自动)加载
    Java思维题
    SSM框架中使用日志框架
    DAC
    SPI接口的FLASH
    晶振测试起振方法
    Jlink不报错的方法
  • 原文地址:https://www.cnblogs.com/baixinL/p/14274981.html
Copyright © 2011-2022 走看看