import a module from node_modules with babel but failed

后端 未结 3 1339
庸人自扰
庸人自扰 2020-12-03 14:04

I wrote a module with es6 and publish to the npm, I want to use it in another project, so I type like this:

import {ActionButton} from \'rcomponents\'
         


        
3条回答
  •  没有蜡笔的小新
    2020-12-03 14:44

    See the babel docs:

    NOTE: By default all requires to node_modules will be ignored. You can override this by passing an ignore regex.

    Generally the expectation is that modules in node_modules will already have been transpiled ahead of time, so they are not processed by Babel. If you will not be doing that, then you need to tell it what files it can process. ignore allows that.

    require("babel/register")({
        // Ignore everything in node_modules except node_modules/rcomponents.
        ignore: /node_modules\/(?!rcomponents)/
    });
    

提交回复
热议问题