Git Product home page Git Product logo

plugin-babel's Introduction

SystemJS

Gitter Backers on Open Collective Sponsors on Open Collective Downloads on JS Delivr

SystemJS is a hookable, standards-based module loader. It provides a workflow where code written for production workflows of native ES modules in browsers (like Rollup code-splitting builds), can be transpiled to the System.register module format to work in older browsers that don't support native modules, running almost-native module speeds while supporting top-level await, dynamic import, circular references and live bindings, import.meta.url, module types, import maps, integrity and Content Security Policy with compatibility in older browsers back to IE11.

Sponsors

Support SystemJS by becoming a sponsor. Your logo will show up here with a link to your website.

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]

Overview

1. s.js minimal production loader

The minimal 2.8KB s.js production loader includes the following features:

  • Loads System.register modules, the CSP-compatible SystemJS module format.
  • Support for loading bare specifier names with import maps via <script type="systemjs-importmap">.
  • Supports hooks for loader customization.

2. system.js loader

The 4.2KB system.js loader adds the following features in addition to the s.js features above:

3. system-node.cjs loader

The system-node.cjs loader is a version of SystemJS build designed to run in Node.js, typically for workflows where System modules need to be executed on the server like SSR. It has the following features:

  • Loading System modules from disk (via file:// urls) or the network, with included caching that respects the Content-Type header.
  • Import Maps (via the applyImportMap api).
  • Tracing hooks and registry deletion API for reloading workflows.
  • Loading global modules with the included global loading extra.

Loading CommonJS modules is not currently supported in this loader and likely won't be. If you find you need them it is more advisable to use Node.js native module support where possible instead of the SystemJS Node.js loader.

Extras

The following pluggable extras can be dropped in with either the s.js or system.js loader:

  • AMD loading support (through Window.define which is created).
  • Named register supports System.register('name', ...) named bundles which can then be imported as System.import('name') (as well as AMD named define support)
  • Dynamic import maps support. This is currently a potential new standard feature.

The following extras are included in system.js loader by default, and can be added to the s.js loader for a smaller tailored footprint:

  • Global loading support for loading global scripts and detecting the defined global as the default export. Useful for loading common library scripts from CDN like System.import('//unpkg.com/lodash').
  • Module Types .css, .wasm, .json module type loading support in line with the existing modules specifications.

Since all loader features are hookable, custom extensions can be easily made following the same approach as the bundled extras. See the hooks documentation for more information.

SystemJS Babel

To support easy loading of TypeScript or ES modules in development SystemJS workflows, see the SystemJS Babel Extension.

SystemJS does not support direct integration with the native ES module browser loader because there is no way to share dependencies between the module systems. For extending the functionality of the native module loader in browsers, see ES module Shims, which like SystemJS, provides workflows for import maps and other modules features, but on top of base-level modules support in browsers, which it does using a fast Wasm-based source rewriting to remap module specifiers.

Performance

SystemJS is designed for production modules performance roughly only around a factor of 1.5 times the speed of native ES modules, as seen in the following performance benchmark, which was run by loading 426 javascript modules (all of @babel/core) on a Macbook pro with fast wifi internet connection. Each test was the average of five page loads in Chrome 80.

Tool Uncached Cached
Native modules 1668ms 49ms
SystemJS 2334ms 81ms

Getting Started

Introduction video.

The systemjs-examples repo contains a variety of examples demonstrating how to use SystemJS.

Installation

npm install systemjs

Documentation

Example Usage

Loading a System.register module

You can load System.register modules with a script element in your HTML:

<script src="system.js"></script>
<script type="systemjs-module" src="/js/main.js"></script>
<script type="systemjs-module" src="import:name-of-module"></script>

Loading with System.import

You can also dynamically load modules at any time with System.import():

System.import('/js/main.js');

where main.js is a module available in the System.register module format.

Bundling workflow

For an example of a bundling workflow, see the Rollup Code Splitting starter project - https://github.com/rollup/rollup-starter-code-splitting.

Note that when building System modules you typically want to ensure anonymous System.register statements like:

System.register([], function () { ... });

are emitted, as these can be loaded in a way that behaves the same as normal ES modules, and not named register statements like:

System.register('name', [], function () { ... });

While these can be supported with the named register extension, this approach is typically not recommended for modern modules workflows.

Import Maps

Say main.js depends on loading 'lodash', then we can define an import map:

<script src="system.js"></script>
<script type="systemjs-importmap">
{
  "imports": {
    "lodash": "https://unpkg.com/[email protected]/lodash.js"
  }
}
</script>
<!-- Alternatively:
<script type="systemjs-importmap" src="path/to/map.json" crossorigin="anonymous"></script>
-->
<script type="systemjs-module" src="/js/main.js"></script>

IE11 Support

IE11 continues to be fully supported, provided the relevant polyfills are available.

The main required polyfill is a Promise polyfill. If using import maps a fetch polyfill is also needed.

Both of these can be loaded conditionally using for example using Bluebird Promises and the GitHub Fetch Polyfill over Unpkg:

<script>
  if (typeof Promise === 'undefined')
    document.write('<script src="https://unpkg.com/[email protected]/js/browser/bluebird.core.min.js"><\/script>');
  if (typeof fetch === 'undefined')
    document.write('<script src="https://unpkg.com/[email protected]/dist/fetch.umd.js"><\/script>');
</script>

located before the SystemJS script itself. The above will ensure these polyfills are only fetched for older browsers without Promise and fetch support.

Note on Import Maps Support in IE11

When using external import maps (those with src="" attributes), there is an IE11-specific workaround that might need to be used. Browsers should not make a network request when they see <script type="systemjs-importmap" src="/importmap.json"></script> during parsing of the initial HTML page. However, IE11 does so. Codesandbox demonstration

Normally this is not an issue, as SystemJS will make an additional request via fetch/xhr for the import map. However, a problem can occur when the file is cached after the first request, since the first request caused by IE11 does not send the Origin request header by default. If the request requires CORS, the lack of an Origin request header causes many web servers (including AWS Cloudfront) to omit the response CORS headers. This can result in the resource being cached without CORS headers, which causes the later SystemJS fetch() to fail because of CORS checks.

This can be worked around by adding crossorigin="anonymous" as an attribute to the <script type="systemjs-importmap"> script.

Community Projects

A list of projects that use or work with SystemJS in providing modular browser workflows. Post a PR.

  • beyondjs.com -TypeScript first meta-framework for universal microfrontends/micronservices.
  • esm-bundle - list of System.register versions for major libraries, including documentation on how to create a System.register bundle for any npm package.
  • es-dev-server - A web server for developing without a build step.
  • import map overrides - Dynamically inject an import map stored in local storage so that you can override the URL for any module. Can be useful for running development modules on localhost against the server.
  • js-env - Collection of development tools providing a unified workflow to write JavaScript for the web, node.js or both at the same time.
  • jspm.org - Package manager for native modules, using SystemJS for backwards compatibility.
  • single-spa - JavaScript framework for front-end microservices.
  • systemjs-webpack-interop - npm lib for setting webpack public path and creating webpack configs that work well with SystemJS.
  • @wener/system - hooks to make System works with npm registry & package.json}

Compatibility with Webpack

Code-splitting builds on top of native ES modules, like Rollup offers, are an alternative to the Webpack-style chunking approach - offering a way to utilize the native module loader for loading shared and dynamic chunks instead of using a custom registry and loader as Webpack bundles include. Scope-level optimizations can be performed on ES modules when they are combined, while ensuring no duplicate code is loaded through dynamic loading and code-sharing in the module registry, using the features of the native module loader and its dynamic runtime nature.

systemjs-webpack-interop is a community-maintained npm library that might help you get webpack and systemjs working well together.

As of [email protected], it is now possible to compile webpack bundles to System.register format, by modifying your webpack config:

{
  output: {
    libraryTarget: 'system', 
  }
}

If using webpack@<5, the following config is needed to avoid rewriting references to the global System variable:

{
  module: {
    rules: [
      { parser: { system: false } }
    ]
  }
}

Using npm packages

Third party libraries and npm packages may be used as long as they are published in a supported module format. For packages that do not exist in a supported module format, here is a list of github repos that publish System.register versions of popular third party libraries (such as react, react-dom, rxjs, etc).

Contributing to SystemJS

Project bug fixes and changes are welcome for discussion, provided the project footprint remains minimal.

Task running is handled by Chomp (https://chompbuild.com).

To run the tests:

npm install -g chomp
chomp test

Changes

For the changelog, see CHANGELOG.md.

License

MIT

plugin-babel's People

Contributors

andyearnshaw avatar behzad888 avatar bhovinga avatar douglasduteil avatar gamtiq avatar grisha avatar guybedford avatar koppor avatar mikz avatar mpfau avatar tyscorp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plugin-babel's Issues

Requiring this file directly for self-executing node.js entrypoint which uses systemjs.

Hi I was playing around with systemjs and I'm wondering why the following doesn't work.

High-level overview of what I'm trying to do:
I'm trying to execute a <es6 node file which 1) requires systemjs using commonjs and 2) configures it to recursively build the remainder of my source code with babel by calling System.import on a single entry file. I'm running into weird bugs related to promises in node.js and I'd like some help debugging the problem. I don't want to use jspm, switching package managers makes me feel a little crazy, maybe someday, but not today. I just want take advantage of those sweet sweet in-memory builds and bundle arithmetic apis.

I have an executable file called ./manage.js with the following contents:

#! /usr/bin/env node
var System = require('systemjs');

System.config({
  map: {
    'plugin-babel': 'node_modules/systemjs-plugin-babel/plugin-babel.js',
    'systemjs-babel-build': 'node_modules/systemjs-plugin-babel/systemjs-babel-node.js',
  },
  transpiler: 'plugin-babel',
});

// requiring an es6/es7 file
System.import('./script.js').then((module) => {
  console.log(module());
});

// my trusty stupid catch-all for errors in promises for node.js environments
// executing this file exits silently if I don't include this
process.on('unhandledRejection', function(error, p) {
  console.error(error.stack || error);
  process.exit(1);
}

This is in a directory with a ./node_modules created with an npm install from this package.json

{
  "name": "system-js-example",
  "license": "MIT",
  "version": "0.0.0",
  "author": "Brian Kim et al.",
  "scripts": {
    "test": "echo \"hahahaa you fucking goof there are no tests psych ๐Ÿ˜˜ love\""
  },
  "dependencies": {
    "babel": "6.5.2",
    "babel-plugin-transform-runtime": "6.8.0",
    "babel-preset-es2015": "6.6.0",
    "babel-preset-react": "6.5.0",
    "babel-preset-stage-2": "6.5.0",
    "babel-register": "6.8.0",
    "babel-runtime": "6.6.1",
    "systemjs": "0.19.29",
    "systemjs-plugin-babel": "0.0.11"
  }
}

and which tries to System.import aka execute the module ./script.js which looks like

export default async function main() {
  console.log('hi world');
  console.log('uhhh');
}

By default, the node process just errors silently. When I add my trusty stupid catch-all for errors in promises for node.js environments, it throws the following error:

ReferenceError: /Users/brian/Projects/systemjs-example/script.js: regeneratorIdentifer is not defined
            at Object.runtimeProperty (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:40371:31)
            at PluginPass.exit (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:40569:46)
            at newFn (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:37237:21)
            at NodePath._call (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:33492:20)
            at NodePath.call (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:33464:19)
            at NodePath.visit (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:33526:10)
            at TraversalContext.visitQueue (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:34770:18)
            at TraversalContext.visitMultiple (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:34728:19)
            at TraversalContext.visit (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:34808:21)
            at Function.traverse.node (/Users/brian/Projects/systemjs-example/node_modules/systemjs-plugin-babel/systemjs-babel-node.js:39580:19)
        Error loading /Users/brian/Projects/systemjs-example/script.js

If I don't use the async/await stuff, system.js works as I expect it to.

Is this my bad? Have I not found the correct documentation yet for how to set up this use case?

Here's a repository ready-made with the stuff I'm talking about:
https://github.com/brainkim/systemjs-example Just:

npm install
./manage.js

Thanks!
Brian Kim

nodejs harmony

Hello,

The issue is related to systemjs/systemjs#1173.

I think systemjs or the plugin doesn't care about the nodejs environment, so it tries to require('path') from current folder.
Any idea ?

Run in Stage 1 Mode

Great work. However I can not for the life of me figure out how to get Stage 1 Features (need decorators) working. I've been trying to import plugins manually in the configuration for most of the day now, and finally had to give up on it. Admittedly I am new to systemjs and babel. Any way you could add Stage 1 or maybe point me in the right direction?

0.0.10: Crash with custom babel-plugin

I'm running a react/relay/graphql-app powered by jspm. Until 0.0.9 I could use a custom loader to load the graphql-schema into relay. After the update in the morning the app simply hangs without any error when I'm trying to load a custom babel-plugin.

It doesn't seem to be specific to my usecase. I've build a testcase where I was trying to load the code of "babel-plugin-transform-react-jsx" as a custom plugin with the same result. The same code runs flawless when it's loaded via package.

My config:

SystemJS.config({
  transpiler: 'plugin-babel',
  packages: {
    'app': {
      'main': 'main.js',
      'meta': {
        '*.js': {
          'loader': 'plugin-babel',
          'babelOptions': {
            'stage1': true,
            'passPerPreset': true,
            'plugins': [
              'babel-plugin-transform-react-jsx',
              'babel-plugin-transform-class-properties',
              'babel-relay-plugin-jspm',
            ],
          },
        },
      },
    },
  },
  map: {
    'babel-relay-plugin-jspm': 'src/utils/babelRelayPlugin.js',
  },
});

Content of babelRelayPlugin.js:

var getbabelRelayPlugin = require('babel-relay-plugin');

var schema = require('../src/data/schema.json!');

module.exports = getbabelRelayPlugin(schema.data);

For me it simply stops to load files in the browser. No error-message :(

Any ideas?

still unclear how to use this plugin

When i include this plugin in my project there still errors with searching of babel files:
ENOENT: no such file or directory, open '/home/pinkiepie/projects/planck/test/mocks/babel-plugin-transform-es2015-template-literals.js
Should i manual add all of plugins in System.config map section?

test: making tests

Hi there I'm curious to know if adding some tests here is welcome.
If it is :

  • do you already have a Systemjs testing module (utility functions)
  • what's your current testing stack (for node and for browsers ?)

I'm having difficulties making this plugin work already so I might need your help for the specs.
Thanks

react preset is not working

I've the following config

    SystemJS.config({
        defaultJSExtensions: true,
        meta: {
            '*.jsx': {
                'loader': 'plugin-babel',
                'format': 'cjs',
                'babelOptions': {
                    'modularRuntime': false,
                    stage1: true,
                    presets: ['babel-preset-react']
                }
            }
        },
        map: {
            'plugin-babel': 'unpkg:systemjs-plugin-babel@latest/plugin-babel.js',
            'systemjs-babel-build': 'unpkg:systemjs-plugin-babel@latest/systemjs-babel-browser.js',
            'babel-preset-react': 'npm:babel-preset-react',
            'react': 'unpkg:[email protected]/dist/react.min.js',
            'react-dom': 'unpkg:[email protected]/dist/react-dom.min.js',
            'react-bootstrap': 'unpkg:[email protected]/dist/react-bootstrap.min.js'
        },
        transpiler: 'plugin-babel',
        paths: {
            '*': 'https://registry.jspm.io/*.js',
            'npm:*': 'https://npm.jspm.io/*.js',
            'github:*': 'https://github.jspm.io/*.js',
            'unpkg:*': 'https://unpkg.com/*',
        },
        packages: {
            'unpkg:*': {
                defaultExtension: false
            },
            './': {
                defaultExtension: false
            }
        }
    });
    SystemJS.import('./app.jsx').then(function (m) {
        console.log(m);
    });

image

plugin-babel does not work as described in documentation

@guybedford : After a long time i have a project where im using "only" systemjs with plugin-babel. The problem is that Systemjs cant initialize the plugin files. I get always an error 404. Its try to load from wrong location:

wrong !

GET http://localhost:3000/babel-runtime/core-js/get-iterator.js 404 (Not Found)
GET http://localhost:3000/babel-plugin-syntax-class-properties.js 404 (Not Found)
GET http://localhost:3000/babel-helper-function-name.js 404  (Not Found)
GET http://localhost:3000/babel-plugin-syntax-decorators.js 404 (Not Found)
GET http://localhost:3000/babel-plugin-syntax-function-bind.js 404 (Not Found)

correct would be (starting with node_modules):

GET http://localhost:3000/node_modules/babel-runtime/core-js/get-iterator.js
GET http://localhost:3000/node_modules/babel-plugin-syntax-class-properties.js 
...
...

What im doing wrong?

Info

Mac OS X El Capitan
Chrome v51
Systemjs v0.19.36
plugin-babel v0.0.13
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <script src="./node_modules/systemjs/dist/system.src.js"></script>
</head>
<body>
<script>
    System.config({
        defaultJSExtensions: true,
        map: {
             // internal libs
            'app/bootstrap': './app/bootstrap.js',
            "app-decorators": "./node_modules/app-decorators/src/app-decorators.js",

             // systemjs and plugin-babel
            'plugin-babel': './node_modules/systemjs-plugin-babel/plugin-babel.js',
            'systemjs-babel-build': './node_modules/systemjs-plugin-babel/systemjs-babel-browser.js',

            // babel plugins
            'babel-plugin-transform-class-properties': './node_modules/babel-plugin-transform-class-properties/lib/index.js',
            'babel-plugin-transform-decorators-legacy': './node_modules/babel-plugin-transform-decorators-legacy/lib/index.js',
            'babel-plugin-transform-function-bind': './node_modules/babel-plugin-transform-function-bind/lib/index.js',

        },
        meta: {
            '*.js': {
                // Custom Presets and Transforms
                babelOptions: {
                    stage1: true,
                    plugins: [
                        'babel-plugin-transform-class-properties',
                        'babel-plugin-transform-decorators-legacy',
                        'babel-plugin-transform-function-bind',
                    ],
                },
            },
        },
        transpiler: 'plugin-babel',
    });

    System.import('app/bootstrap');

</script>
</body>
</html>

0.0.10 - TypeError: Cannot read property 'match' of null

The update to 0.0.10 is throwing an error when I run jspm bundle index.js -id

This previously worked on 0.0.9:

Building the bundle tree for index.js...

err  TypeError: Cannot read property 'match' of null
at /Users/me/project/node_modules/systemjs-builder/lib/sourcemaps.js:62:25
at Array.forEach (native)
at SourceMapConsumer_eachMapping [as eachMapping] (/Users/me/project/node_modules/source-map/lib/source-map-consumer.js:155:14)
at /Users/me/project/node_modules/systemjs-builder/lib/sourcemaps.js:61:24
at Array.forEach (native)
at exports.concatenateSourceMaps (/Users/me/project/node_modules/systemjs-builder/lib/sourcemaps.js:42:19)
at createOutput (/Users/me/project/node_modules/systemjs-builder/lib/output.js:63:21)
at exports.writeOutputs (/Users/me/project/node_modules/systemjs-builder/lib/output.js:150:16)
at /Users/me/project/node_modules/systemjs-builder/lib/builder.js:607:14
at tryCatcher (/Users/me/project/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/me/project/node_modules/bluebird/js/release/promise.js:502:31)
at Promise._settlePromise (/Users/me/project/node_modules/bluebird/js/release/promise.js:559:18)
at Promise._settlePromise0 (/Users/me/project/node_modules/bluebird/js/release/promise.js:604:10)
at Promise._settlePromises (/Users/me/project/node_modules/bluebird/js/release/promise.js:683:18)
at Promise._fulfill (/Users/me/project/node_modules/bluebird/js/release/promise.js:628:18)
at Promise._resolveCallback (/Users/me/project/node_modules/bluebird/js/release/promise.js:423:57)

What other info should I provide?

npm:debug

Suggested so we can get rid of the insane amounts of console noise.

Disable es2015 while still being able to build

Hi all,

I'm trying to figure out how to disable es2015 transpiling and still get a single file build through rollup in jspm@beta. While looking at its source, plugin-babel comes with es2015: true by default which I can override in.

I made a fork of jspm-react-component-demo that sets "es2015": false in `"babelOptions" and it stops the transpiling of es2015 features as expected but it doesn't bundle everything into one file as rollup would do, here's the output:

jspm-react-component-demo [es2015-false*] $ jspm build jspm-react-component - react dist/jspm-react-component.js   --format umd --global-name jspmReactComponent --global-deps "{'react':'React'}" --skip-source-maps
     Creating the single-file build for jspm-react-component - react...

       โ”€โ”€ jspm-react-component/component.js

ok   Fully-optimized - entire tree built via Rollup static optimization.

ok   Built into dist/jspm-react-component.js, unminified as umd.

This conditional seems to be dealing with it but for some reason it's not outputting the full bundle.

I don't know if this should make any difference at all but I've also tried including babel-plugin-transform-es2015-modules-systemjs like you do when es2015: true but I get the same result.

Would you have any hints on how to fix this if it's an issue or what am I missing if I'm doing the wrong thing? :)
Thanks!
Darรญo

Unable to hit breakpoint

Hello,

I have difficulties to debug my code using plugin-babel.
If i put a breakpoint in my es6 file test.js, the breakpoint is never hit by chrome dev. I must insert debugger line and the debugger breaks in test.js!transpiled.
If I put a breakpoint in test.js!transpiled, the breakpoint doesn't work.

Could you tell me how do you debug the es6 code ? I don't see any sourcemap.
Maybe changing extension in test.js!transpiled to test.js!transpiled.js could solve the breakpoint problem.

Thank you in advance for your help.

How to specify version of babel?

I am currently getting hit by a named export hoisting issue using this plugin. I see that it has been fixed here: babel/babel#3594. I am assuming that I am not using the latest version of babel and that is why I am seeing this locally. Is there a way to change the babel version that this plugin uses?

Plugins aren't bundled

It seems that my babel plugins aren't bundled unless I add them explicitly to the bundle command.

For example:

jspm bundle myModule + babel-plugin-transform-decorators-legacy bundle.js

Is this working as intended?

jspm bundle issue after upgrading to 0.0.4

I am trying to bundle couple of libraries in my dev environment to speed up loading time. After I have upgraded to 0.0.4, I am getting following errors for libraries written in es6 code. Following command

jspm bundle systemjs-hot-reloader src/vendor/systemjs-hot-reloader.js --inject

throws an error

Building the bundle tree for systemjs-hot-reloader...

err  MultipleErrors: Error on instantiate for npm:[email protected]/babel-helpers/createClass.js at file:///Volumes/DATA/Bhavin/Projects/lab/gembatech/src/jspm_packages/npm/[email protected]/babel-helpers/createClass.js
  Loading github:capaj/[email protected]/hot-reloader.js
  <compiler-parse-input>:17:2: Unexpected token )

updating the module to 0.0.3 throws similar error. However, it goes away when I roll it back to 0.0.2.

ReferenceError: state is not defined

I am getting an error simply trying to reference a file:

err  ReferenceError: file:///Users/paul/Projects/jspm-test/lib/middleware/response_time.js: state is not defined
    at getRuntimeMarkDecl (file:///Users/paul/Projects/eyecue/jspm-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:40043:235)

This is the file:

'use strict'

function * responseTime (next) {
  let start = new Date()
  yield next
  var ms = new Date() - start
  this.set('X-Response-Time', ms + 'ms')
}

export default function init (app) {
  app.use(responseTime)
}

This is the import statement:

import responseTime from './response_time'

jspm with plugin-babel and react preset: "cannot read property 'transform' of undefined"

I'm getting the above error in the Chrome console at system.js 4 @system.src.js:4837
I've got the jsx preset installed in jspm_packages along with the babel-plugin.
My config.js has the "transpiler" set as "plugin-babel".
My config.js has "presets": [ "react" ] and "blacklist": [] under "babelOptions."

In my "main.js" file I have:

  • import React from 'react';
  • import ReactDom from 'react-dom';
    (both are installed in jspm_packages)
  • import showNavbars from '/path' (imports a function)
  • showNavbars();

On my index.html I have:

<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
    System.import('/assets/js/main.js');
</script>

I'm not even sure if this is a babel-plugin issue or not. I'm getting the error from system.js, so I logged it there also and under jspm.

Async/await is not working with this pattern

This one works:

//boot.js
var main = require('./main.js')

main.boot()

//main.js

export async function boot() {
  await new Promise(function(resolve, reject) {
    console.log('hello world');
    setTimeout(function() {
      resolve();
    }, 1000);
  })
  console.log('hello world after 1s!');
}

This one works with webpack but systemjs:

//boot.js
var main = require('./main.js')

//main.js

(async function boot() {
  await new Promise(function(resolve, reject) {
    console.log('hello world');
    setTimeout(function() {
      resolve();
    }, 1000);
  })
  console.log('hello world after 1s!');
})()

Not sure is it an issue

Edit:
Works after adding this:
export var p = 5;
More precisely, in configuration:

meta: {
  './js/main.js': {
    format: 'esm'
  }
}

babelOptions.sourceMaps or sourceMap?

https://github.com/systemjs/plugin-babel/blob/master/plugin-babel.js#L49 uses sourceMaps:

var defaultBabelOptions = {
  modularRuntime: true,
  sourceMaps: true,
  es2015: true,
  stage3: true,
  moduleName: false
};

but https://github.com/systemjs/plugin-babel/blob/master/plugin-babel.js#L140 uses sourceMap:

    var output = babel.transform(load.source, {
      plugins: plugins,
      presets: presets,
      filename: load.address,
      sourceMap: babelOptions.sourceMap,
      inputSourceMap: load.metadata.sourceMap,

unable to use esm plugins unless explicitly setting babelOptions.plugins to []

if I write a module in ESM and then add it as a babel plugin, when the module gets imported it tries to transpile it using itself as a plugin ... and then jspm crashes.
should it always be necessary to override babelOptions.plugins on the module? or should plugin-babel be changed to either a) not use any babel plugins for transpiling babel plugins, or b) maybe just ignore itself

XHR error loading npm:[email protected]

My app works great with the following jspm conf but when I run tests with karma it have this error:

Error: XHR error loading npm:[email protected]
    Error loading npm:[email protected]

Here is the jspm.cconfig.js:

SystemJS.config({
  packages: {
    'src': {
      'defaultExtension': 'js'
    }
  },
  transpiler: 'plugin-babel'
});

SystemJS.config({
  packageConfigPaths: [
    'npm:@*/*.json',
    'npm:*.json',
    'github:*/*.json'
  ],
  map: {
    'angular': 'npm:[email protected]',
    'assert': 'github:jspm/[email protected]',
    'babel': 'npm:[email protected]',
    'buffer': 'github:jspm/[email protected]',
    'child_process': 'github:jspm/[email protected]',
    'core-js': 'npm:[email protected]',
    'events': 'github:jspm/[email protected]',
    'fs': 'github:jspm/[email protected]',
    'http': 'github:jspm/[email protected]',
    'module': 'github:jspm/[email protected]',
    'net': 'github:jspm/[email protected]',
    'path': 'github:jspm/[email protected]',
    'plugin-babel': 'npm:[email protected]',
    'process': 'github:jspm/[email protected]',
    'stream': 'github:jspm/[email protected]',
    'tty': 'github:jspm/[email protected]',
    'url': 'github:jspm/[email protected]',
    'util': 'github:jspm/[email protected]'
  },
  packages: {
     ...
  }
});

Though, if I add

  paths: {
    "github:*": "/base/jspm_packages/github/*",
    "npm:*": "/base/jspm_packages/npm/*"
  }

and then run the tests, I have a different error:

Error: TypeError: setting a property that has only a getter
        at j (:2)
        at i (:2)
        at :2
        at :15
        at j (:2)
...

Support for module transforms only.

With Canary at 96% es6 complete, I'd like to use es6-module-loader with babel only transpiling the module import/export statements. I believe this will be needed as we get closer to all browsers being nearly es6 complete, but still needing module loading.

To be clear, my goal is to use the <script type='module'> tag which is likely to be the first native browser module loading. Thus my use of es6-module-loader, currently with traceur which unfortunately transpiles everything.

Let me know if there is another way to achieve this!

question: extracting build process to a separare module

Hi there

I had a very hard time understanding how this plugin works. I'm still a bit moved by the forced fixed Babel version and the use of traceur to compile concat Babel sources for node and the browser.

Can you give more input over those choices ?

  • Can the build process be extracted from the plugin itself ?
  • Do we need two transpiler to handle code concatenation ?
  • Can't we use already installed Babel for the job ?
  • Is the Babel configuration file still required if we, instead of a JSPM building make, a file with concatenated Babel code in Systemjs format ?

Any way I'm currently forking your build step to a separate CLI to be able to bundle any Babel and babel plugin version I want in systemjs ready format.
It will ideally look like that :

# using the .babelrc config file + the installed files in the node_modules (if possible)
systemjs-babel-build -o my-systemjs-babel-build.js

Possible to change file extension

Currently I have a very large project and running babel on everything is getting a bit slow. With my code being over 99% es5 I don't need babel to run on every js file. So I created a new mapping

'*.es': {
    'loader': 'plugin-babel',
    'format': 'cjs',
    'babelOptions': {
        'modularRuntime': false
    }
}

This makes it so I only need to transpile es files. But I need a way to also convert their extension to js as es is not a valid extension type. The babel cli allows for this but I do not know how to go about this in systemjs.

Unable to use it - Uncaught ReferenceError: require is not defined in plugin-babel.js

Hi,

I'm trying to use this plugin in order to use Babel 6 with SystemJs (without jspm). Probably I'm doing something terribly wrong, because even though I follow docs, I cannot make it work. This is what I have in my index.html:

  • reference to SystemJS v0.19.3

<script src="bower_components/system.js/dist/system.js"></script>

  • script block that configures SystemJS:
<script>
  System.config({
    map: {
      'plugin-babel': '../node_modules/systemjs-plugin-babel/plugin-babel.js',
      'systemjs-babel-build': '../node_modules/systemjs-plugin-babel/systemjs-babel-browser.js'
    },
    transpiler: 'plugin-babel'
  });
  System.import('app.js');
</script>

Paths are OK. When I enter the page, /node_modules/systemjs-plugin-babel/plugin-babel.js is downloaded, but I crashes on first line (require is undefined):

var babel = require('systemjs-babel-build').babel;

Thanks for help.
Pawel

SyntaxError with v0.0.3

I get the following exception with [email protected]:

Uncaught (in promise) SyntaxError: http://localhost:3000/jspm_packages/npm/[email protected]/babel-helpers/slicedToArray.js: Unexpected token (37:2)

Seems like there are some parenthesis missing for the IIFE to work?

Cannot import a module when using the browser test example code

To test and understand how to use the plugin, I am just trying to import a module as a dependency in the code used by test/manual.html. Despite having read the documentation of Babel, SystemJS and plugin-babel, trying different configuration options, I have never managed to make it work.

So here the simplest case based on the current code of the test:

Added test/foo-mod.js:

export default var foo = 7;

Modified test/manual.js:

import foo from './foo-mod'; // --> 404 Not Found
//import foo from './foo-mod.js'; // --> Unexpected token (1:15)

export var p = 5;

The first line throws Not Found whereas the path is correct (except for the .js extension). The second one throws unexpected token when .js is explicitely added.

Isn't the specific build of Babel of this plugin supposed to make this work out of the box? Is there any additional preset or plugin to enable? What am I missing?

(I have made a branch in my fork with the above changes for reproducing purpose: https://github.com/gentooboontoo/plugin-babel/tree/import-test).

problem when I try to run jspm-react boilerplate codebase

When running unit tests, I get:
(SystemJS) /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:136
$traceurRuntime.canonicalizeUrl = canonicalizeUrl;
^
ReferenceError: $traceurRuntime is not defined
at /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:136:3
at /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:140:3
at /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:3859:23
at /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:42896:3
at Object.exports.runInThisContext (vm.js:54:17)
Evaluating /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js
Error loading /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js as "systemjs-babel-build" from /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/plugin-babel.js
Error loading /var/www/zahrajeme.cz/public/routes/home.js
(SystemJS) /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:136
$traceurRuntime.canonicalizeUrl = canonicalizeUrl;
^
ReferenceError: $traceurRuntime is not defined
at public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:136:3
at public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:140:3
at public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:3859:23
at public/jspm_packages/npm/[email protected]/systemjs-babel-node.js:42896:3
at Object.exports.runInThisContext (vm.js:54:17)
Evaluating /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js
Error loading /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/systemjs-babel-node.js as "systemjs-babel-build" from /var/www/zahrajeme.cz/public/jspm_packages/npm/[email protected]/plugin-babel.js
Error loading /var/www/zahrajeme.cz/public/routes/home.js

I am using babel-why would it try to use traceur?

applyMap -- undefined is not a function

When I run jspm install plugin-babel I keep getting this error:

(I added some console.log statements in build.js line 251)

     Updating registry cache...
     Looking up npm:systemjs-plugin-babel
     Downloading npm:[email protected]
**map  { 'systemjs-babel-build':
   { browser: './systemjs-babel-browser.js',
     node: './systemjs-babel-node.js' } }
 m in map  systemjs-babel-build**

err  TypeError: undefined is not a function
         at applyMap (/Users/.../node_modules/jspm/lib/build.js:252:15)
         at /Users/.../node_modules/jspm/lib/build.js:528:30
         at String.replace (native)

warn Installation changes not saved.'```

btw, What would you consider a clean install if I were going to try this from scratch?
Something like this?:
    npm install systemjs
    npm install jspm
    jspm install plugin-babel

Decorator plugin doesn't apply to imported dependencies

For jspm v0.17.22:
When using babel-plugin-transform-decorators-legacy inside of the meta config for *.js, decorators work as expected in a project. Dependencies imported from a project source file, though, throw an error during parsing if they contain decorators (unexpected token on the '@'). The syntax of both decorators is the same.

For example:

function decorator(){}

/* Works fine */
@decorator
export class Something {}

/* This file contains decorators as well, and breaks because of Unexpected Token '@' */
import {ArvaRouter} from 'arva-js/routers/ArvaRouter.js';

The meta part of jspm.config.js is as follows:

      "meta": {
        "*.js": {
          "loader": "plugin-babel",
          "babelOptions": {
            "plugins": [ "babel-plugin-transform-decorators-legacy" ]
          }
        }
      }

The error thrown when an imported dependency uses decorators:

     Creating the single-file build for src/main.js...

err  Error on translate for github:bizboard/arva-js@1.0.3/routers/ArvaRouter.js at file:///[..]/ArvaRouter.js
  Loading app/main.js
  SyntaxError: file:///[..]/ArvaRouter.js: Unexpected token (16:0)
  14 | import AnimationController          from 'famous-flex/AnimationController.js';
  15 | 
> 16 | @provide(Router)
     | ^
  17 | export class ArvaRouter extends Router {
  18 | 
  19 |     constructor() {
    at Parser.pp.raise (file:///[..]/[email protected]/systemjs-babel-node.js:29141:15)

I created a repro case that shows how decorators work in project source files, but not in imported dependencies, which can be found here.

Support for Bluebird coroutines

If users want to use Bluebird promises for performance, we should provide an easy option to use this transformer without having to do more than setting the option and installing bluebird.

Update Babel

Node 6 support should be coming with the next update

What is the purpose of this plugin?

I'm having a really hard time understanding what the difference is between using this plugin and just using babel directly. What's the difference between transpiler: 'babel' and transpiler: 'plugin-babel' Could you please clarify?

Error running jspm build: "Error: Cannot find module 'process'"

Hi,

I'm trying to build a static version of an application using jspm 0.17-beta.27 and plugin-babel 0.0.13. On my development system everything works just fine, but when I try to run the build process on the target system, I can't seem to get it to work.

To reproduce, I assembled a test case here: https://github.com/nimajneb/jspm-babel-test

$ jspm build src/app.js 
     Creating the single-file build for src/app.js...

err  (SystemJS) module.js:338
      throw err;
      ^
  Cannot find module 'process'
  module.js:338
      throw err;
      ^
  Error: Cannot find module 'process'
      at Function.Module._resolveFilename (module.js:336:15)
      at Function.Module._load (module.js:278:25)
      at Module.require (module.js:365:17)
      at require (module.js:384:17)
      at p (/home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:3125)
      at i (/home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:1851)
      at /home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:2261
      at /home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:41360:17
      at l (/home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:2183)
      at i (/home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:1817)
      at /home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:2261
      at /home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:9943:17
      at l (/home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:2183)
      at a (/home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:959)
      at p (/home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:3198)
      at /home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/systemjs-babel-node.js:1:4104
  Evaluating /home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/plugin-babel.js
  Error loading /home/benjamin/jspm-babel-test/jspm_packages/npm/[email protected]/plugin-babel.js

The target system only has node 0.12.2 and npm 3.3.4 installed, whereas on my development system I use node 5.9.0 and npm 3.8.3. However, I couldn't find any information on minimum requirements of the babel plugin. Could that be an issue?

Cheers,
Benjamin

babelOptions are ignored

I'm getting this in the chrome console trying to load a large file...

VM101480:27 [BABEL] Note: The code generator has deoptimised the styling of "http://host.com:8080/js/util/redactor/redactor.js" as it exceeds the max of "100KB". window.console.error 
@ VM101480:27b.normalizeOptions 
@ systemjs-babel-browser.js:7b 
@ systemjs-babel-browser.js:7b.default 

I can't figure out where to add the 'compact: false' option. I have tried numerous places in SystemJS.config() in jspm.config.js to no avail...

SystemJS.config({
  transpiler: "plugin-babel",
  babelOptions: {
    "modularRuntime": false,
    "compact": false
  },
  meta: {
    "*.js": {
      "babelOptions": {
        "compact": false
      }
    }
  },
  packages: {
    "hub": {
      "format": "cjs",
      "main": "app.js",
      "meta": {
        "*.js": {
          "loader": "plugin-babel",
          "babelOptions": {
            "compact": false
          }
        }
      }
    }
  }
});

evergreen build variation

We should definitely have an evergreen easy preset version of this plugin. My apologies to all the users who've suggested this already.

Inline sourcemaps not appended to file in node.js environment

Source maps appears to be working in the browser but not in node. It looks to me like the transformation simply ignores the sourceMaps: 'inline' option, as the result does seem to have a sourcemaps object, but it was never appended to the output file.

Is this work in a webworker ?

Hi.
I have an angular2 application that I try to convert to webworker.

But when Systemjs try to load an es6 file I have this error.

Error loading http://localhost:8000/systemjs-babel-build as "systemjs-babel-build" from http://localhost:8000/jspm_packages/npm/[email protected]/plugin-babel.js

Everything works fine when I load the same application without the webworker.

I have try to understand what's going on, you seems to load two different files for the browser and node.

Maybe in worker mode the wrong one is loaded ?

If I missed something feel free to ask me.

PS: Sorry for my bad english :(

Unexpected token {

Hi guys I've been running into this occasionally since setting my transpiler to babel. If I refresh it goes away and it's different files most of the time. I can go hours without seeing it or see it twice in two reloads. I'm not sure what the issue is.

system.src.js:122 Uncaught (in promise) Error: (SystemJS) https://localhost.catalystapps.com:8080/ui/app/pages/site/detail/macros/macros.js: Unexpected token (20:48)
      18 |  prevVals: null,
      19 | 
    > 20 |  init: function(applyValues, saveDoc, onChange) {
         |                                                 ^
      21 |      mod.applyValues = applyValues
      22 |      mod.saveDoc = saveDoc
      23 |      mod.onChange = onChange
'*.js': {
    'loader': 'plugin-babel',
    'format': 'cjs',
    'babelOptions': {
        'modularRuntime': false
    }
}

Self-host

With the following configuration in jspm.config.js in build-babel:

  packageConfigPaths: [
    "npm:@*/*.json",
    "npm:*.json",
    "github:*/*.json",
    "plugin-babel/package.json"
  ],

  babelOptions: {
    stage2: false,
    stage3: false,
    es2015: false
  },

  paths: {
    "plugin-babel/": "../"
  },

  transpiler: "plugin-babel",

We can roughly self-host the project.

Unfortunately somehow the source being output looks like:

export { * as babel, modulesRegister, externalHelpers, runtimeTransform, presetES2015, presetES2015Register, default as presetStage3, default as presetStage2 };

Where * as babel is an invalid rewriting.

If I remove all plugins and presets I still get that output, but if I run Babel on the commandline I don't get this at all. Debugging that issue should enable a full Babel workflow for self-hosting, which would be a plus.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.