krakenjs/beaver-logger

Importing server-side module error

nkg448 opened this issue · 3 comments

When I try doing

let beaverLogger = require('beaver-logger/server');

In my app js file, I get the following import error on start:

(function (exports, require, module, __filename, __dirname) { export * from './server';

SyntaxError: Unexpected token import

I've tried adding Babel 7 to my project, tried various babel config settings to support babel transpilation of imported modules, no luck. My app is fairly simple, so there shouldn't be any weird left-field issues. I'm using Node 8.12 I believe, beaver-logger@4.0.5. Any ideas?

I recommend downgrading to 3.0.17 as i think it was with better functionalities. (not sure what happened to transitions). I am personally going to do that.

I got 4.0.5 to work by using webpack + babel:

const nodeExternals = require("webpack-node-externals");

module.exports = {
  target: "node",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: require.resolve("babel-loader"),
        },
      },
    ],
  },
  externals: [
    nodeExternals({
      modulesFromFile: true,
      whitelist: [/^beaver-logger\//],
    }),
  ],
};
module.exports = {
  presets: [
    [
      require("@babel/preset-env"),
      {
        targets: {
          node: "current",
        },
      },
    ],
  ],
};

Yikes looks like Babel isn't transforming those imports. I'll push a fix this afternoon. Thanks for the heads up!

Should be fixed now. Can you please test once more?

(not sure what happened to transitions)

beaver-logger v4 has been stripped back to focus on the thing it does well: batching and dispatching events from the browser to the server.

If you'd like to use transitions on your app, please feel free to borrow the code from v3: https://github.com/krakenjs/beaver-logger/blob/a281c8f69863d78c5aff0f5104d69041ec388c93/client/transitions.js -- it should work pretty well outside of the core beaver-logger module. Or if you'd like to expose this as a separate optional module I'd be more than happy for you to use the above code as a starting point. :)