【问题标题】:This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom'此实验语法需要启用解析器插件:'exportDefaultFrom'
【发布时间】:2018-08-17 04:44:51
【问题描述】:

This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom'

我在尝试将整个应用程序从 react v15.6 移动到 v16.2 时遇到上述错误,方法是使用来自 facebook 的迁移工具,例如 jscodeshift

【问题讨论】:

标签: javascript reactjs facebook jscodeshift


【解决方案1】:

将 @babel/plugin-proposal-export-default-from (https://git.io/vb4yH) 添加到 Babel 配置的“插件”部分以启用转换。

【讨论】:

    【解决方案2】:

    我解决了这个问题。

    const parser = require('./src/parser');
    const jscodeshift = require('jscodeshift').withParser(parser);
    

    ./src/parser:

    'use strict';
    
    const babylon = require('babylon');
    
    // These are the options that were the default of the Babel5 parse function
    // see https://github.com/babel/babel/blob/5.x/packages/babel/src/api/node.js#L81
    
    const options = {
      sourceType: 'module',
      allowHashBang: true,
      ecmaVersion: Infinity,
      allowImportExportEverywhere: true,
      allowReturnOutsideFunction: true,
      plugins: [
        'estree',
        'jsx',
        'asyncGenerators',
        'classProperties',
        'doExpressions',
        'exportExtensions',
        'functionBind',
        'functionSent',
        'objectRestSpread',
        'dynamicImport',
        'nullishCoalescingOperator',
        'optionalChaining',
        'exportDefaultFrom'
      ],
    };
    
    /**
     * Wrapper to set default options
     */
    exports.parse = function parse (code) {
      return babylon.parse(code, options);
    };
    

    请将“exportDefaultFrom”添加到插件中。

    【讨论】:

      猜你喜欢
      • 2018-09-17
      • 2021-06-01
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多