question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In most of my projects that are not performance critical I am using Babel. Just tried out nexe on one of these projects but it has issues at least with ES7 syntax, e.g. module.exports = async function (cmdArgs) {.

The file that I am building has babel defined as follows:

//run.js
require('babel/register')({
  experimental: true,
  loose: true
});

var nodegitFile = require('./nodegit');

nodegitFile(['tests/fixtures/example.txt']);

and running node run.js works fine.

The error I am getting on nexe -i run.js is:

----> bundle project/blame-history/run.js
events.js:141
      throw er; // Unhandled 'error' event
            ^
Error: Parsing file project/blame-history/nodegit.js: Unexpected token (5:23)
    at Deps.parseDeps (/Users/markus/npm/lib/node_modules/nexe/node_modules/module-deps/index.js:418:28)
    at fromSource (/Users/markus/npm/lib/node_modules/nexe/node_modules/module-deps/index.js:361:48)
    at /Users/markus/npm/lib/node_modules/nexe/node_modules/module-deps/index.js:356:17
    at ConcatStream.<anonymous> (/Users/markus/npm/lib/node_modules/nexe/node_modules/module-deps/node_modules/concat-stream/index.js:32:43)
    at emitNone (events.js:72:20)
    at ConcatStream.emit (events.js:163:7)
    at finishMaybe (/Users/markus/npm/lib/node_modules/nexe/node_modules/module-deps/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:460:14)
    at endWritable (/Users/markus/npm/lib/node_modules/nexe/node_modules/module-deps/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:469:3)
    at ConcatStream.Writable.end (/Users/markus/npm/lib/node_modules/nexe/node_modules/module-deps/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:436:5)
    at Transform.onend (/Users/markus/npm/lib/node_modules/nexe/node_modules/module-deps/node_modules/readable-stream/lib/_stream_readable.js:523:10)

Any chance to get nexe to support Babel?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
defunctzombiecommented, Jun 18, 2016

For anyone else that stumbles here wondering how to package up newer js here is an approach that will work.

tl;dr; use webpack to create a single js file and package that with nexe

Use webpack to create a single js file starting from some entry point.

Below is a webpack.config.js that I used.

const webpack = require('webpack');

module.exports = {
    entry: ['babel-polyfill', './cli.js'],
    output: {
        path: "/tmp",
        filename: 'build.js',
    },
    target: 'node',
    plugins: [
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.optimize.UglifyJsPlugin(),
    ],
    module: {
        loaders: [{
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel',
            query: {
                plugins: [
                    'transform-class-properties',
                    'transform-async-to-generator',
                    'transform-object-rest-spread',
                ],
                presets: ['es2015'],
            },
        }, {
            test: /\.json$/,
            loader: 'json',
        }],
    },
};

You will need to ensure you have the correct dependencies in your package.json. Here is an example from mine.

{
  "name": "bagstore-cli",
  "version": "0.0.0",
  "dependencies": {
    "ansi": "0.3.1",
    "babel-cli": "6.9.0",
    "babel-core": "6.9.0",
    "babel-loader": "6.2.4",
    "babel-plugin-transform-async-to-generator": "6.8.0",
    "babel-plugin-transform-class-properties": "6.9.0",
    "babel-plugin-transform-es2015-modules-commonjs": "6.8.0",
    "babel-plugin-transform-object-rest-spread": "6.8.0",
    "babel-preset-es2015": "6.9.0",
    "commander": "2.9.0"
  },
  "devDependencies": {
    "memory-fs": "0.3.0",
    "webpack": "1.13.1"
  },
}

In my case cli.js was my entrypoint. Webpack will “follow” your import or require expressions and you will end up with a single file /tmp/build.js which is all of the code for your CLI app packaged up in a single js file.

With the above config file, run the webpack CLI command per usual. It will produce /tmp/build.js which is your entire app as a single js file suitable for running with node. (i.e. node /tmp/build.js to test it).

I have not taken the step to actually package it with nexe (since having a single JS file was good enough for my use case) but it should be relatively straight forward to do so with the final js file.

0reactions
calebboydcommented, Jul 17, 2017

Bundling is decoupled from nexe in nexe@beta

Read more comments on GitHub >

github_iconTop Results From Across the Web

Babel · The compiler for next generation JavaScript
Babel is a JavaScript compiler. · Put in next-gen JavaScript · Get browser-compatible JavaScript out · Current Sponsors · Base Support · Gold...
Read more >
Babel is a compiler for writing next generation JavaScript.
Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain features...
Read more >
General Support Functionality — Babel 2.11.0 documentation
Babel ships a few general helpers that are not being used by Babel itself but are useful in combination with functionality provided by...
Read more >
Documentation - Using Babel with TypeScript
How to create a hybrid Babel + TypeScript project. ... By using babel's support for TypeScript, you get the ability to work with...
Read more >
Tooling - styled-components
Babel Plugin. This plugin adds support for server-side rendering, minification of styles, and a nicer debugging experience.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found