javascript - How to use ES6 import with hyphen - Stack Overflow

I really don't know how to do this and not sure how to google either. Right now I have this let so

I really don't know how to do this and not sure how to google either.

Right now I have this

let source = require('vinyl-source-stream');

I would like to change to be import but this doesn't work

import {'vinyl-source-stream' as source} from 'vinyl-source-stream';

I really don't know how to do this and not sure how to google either.

Right now I have this

let source = require('vinyl-source-stream');

I would like to change to be import but this doesn't work

import {'vinyl-source-stream' as source} from 'vinyl-source-stream';
Share Improve this question asked Nov 5, 2015 at 18:54 toytoy 12.2k29 gold badges101 silver badges181 bronze badges 2
  • 1 What does 'vinyl-source-stream' look like? i.e. would it work without hyphens so hyphens are really the issue here? – Paul S. Commented Nov 5, 2015 at 18:56
  • It's npm package npmjs./package/vinyl-source-stream – toy Commented Nov 5, 2015 at 18:57
Add a ment  | 

2 Answers 2

Reset to default 4

If that module even supports the ES6 import/export system, then what you want is this:

import source from 'vinyl-source-stream';

Your version is attempting to import an exported value named vinyl-source-stream from the module; instead, you just want the module itself to be imported (into an object named source in this case).

If you want everything in the module imported, instead of just the default exports, use this instead:

import * as source from 'vinyl-source-stream';

But neither of those will work if the module isn't actually written to use the new system.

This library doesn't use the ES2015 module system. It doesn't export at all, so you can't import it or from it.

This library uses the CommonJS module pattern (as can be seen in the source) and is meant to be requireed.

You could import the library with:

import form 'vinyl-source-stream';

which will cause the code to be executed, but that will be useless in this case since nothing (useful) will happen - in fact, you'll probably get a runtime exception due to undefined module.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744859967a4597640.html

相关推荐

  • javascript - How to use ES6 import with hyphen - Stack Overflow

    I really don't know how to do this and not sure how to google either. Right now I have this let so

    2天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信