How can I get the import statements to work in nodejs? I keep reading that you set an experimental flag, but how do I do that? Can I get it to be permanent?
Yeah I tried upgrading to node 12 this past weekend and was still getting errors suggesting I use an experimental flag. But I can read your link and look into it more
As also seen in the link that you send, it is only supported natively in modules :-). Thus not in the sample code used in the post ... But beside that you are right.
I think one of the purposes with Babel here is to compile to an earlier ES version, without import/export syntax.
If you look in the compiled js files, you will probably see require and module.export (this can vary on what Babel is set to build for)
This way you could use earlier node versions and not limit it to just one.
I would say this is more useful in modules than services, as a service could just be locked to one node version, whereas modules are likely to be used in many different versions of node :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How can I get the import statements to work in nodejs? I keep reading that you set an experimental flag, but how do I do that? Can I get it to be permanent?
Is your babel config taking care of it?
Node12+ has native support for import/export:
thecodebarbarian.com/nodejs-12-imp...
Yeah I tried upgrading to node 12 this past weekend and was still getting errors suggesting I use an experimental flag. But I can read your link and look into it more
As also seen in the link that you send, it is only supported natively in modules :-). Thus not in the sample code used in the post ... But beside that you are right.
As Daniel said babel here is to compile es6 to es5, like import/export syntax.
it will create a dist folder with compiled code.
I think one of the purposes with Babel here is to compile to an earlier ES version, without import/export syntax.
If you look in the compiled js files, you will probably see
require
andmodule.export
(this can vary on what Babel is set to build for)This way you could use earlier node versions and not limit it to just one.
I would say this is more useful in modules than services, as a service could just be locked to one node version, whereas modules are likely to be used in many different versions of node :)