Skip to content
Advertisement

Tag: es6-modules

Natively import ES module dependencies from npm without bundling/transpiling first-party source

Background I’m trying to create a “buildless” JavaScript app, one where I don’t need a watch task running to transpile JSX, re-bundle code, etc every time I save any source file. It works fine with just first-party code, but I’m stuck when I try to import dependencies from npm. Goal I want to achieve this kind of workflow: npm install

Using ES Modules with babel-standalone

Quoting babel docs https://babeljs.io/docs/en/babel-standalone#usage : “If you want to use your browser’s native support for ES Modules, you’d normally need to set a type=”module” attribute on your script tag. With @babel/standalone, set a data-type=”module” attribute instead” For some reason though, when including my main index.js file (which imports other js / jsx files using import), it seems like babel is

Is there a way to “npm init” an ES module?

All modern versions of Node need to run packages as modules is “type”: “module” in package.json, but I don’t see any flags for npm init or yarn init that will add that property. Is there a flag for either package manager or an easy way to add the value to package.json (i.e., npm package-property set type module or something similar)?

Import ‘.json’ extension in ES6 Node.js throws an error

We’re trying to use the new ways of exporting and importing modules for ES6 with Node.js. It’s important for us to get the version number from the package.json file. The following code should do that: However, on execution the following error is thrown: Is there something we’re missing? Is the extension .json not supported? Is there another way to retrieve

Advertisement