neutrinojs / neutrino

Create and build modern JavaScript projects with zero initial configuration.
https://neutrinojs.org
Mozilla Public License 2.0
3.95k stars 214 forks source link

@neutrino/library ReferenceError: regeneratorRuntime is not defined #1382

Closed Tassfighter closed 5 years ago

Tassfighter commented 5 years ago

regeneratorRuntime.mark(function _callee() { ^

ReferenceError: regeneratorRuntime is not defined at /mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:211:7 at /mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:242:6 at Module../src/server/index.js (/mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:246:2) at webpack_require (/mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:30:30) at Module../src/index.js (/mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:108:65) at webpack_require (/mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:30:30) at Object.0 (/mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:279:18) at __webpack_require__ (/mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:30:30) at /mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:94:18 at /mnt/work/gitlab/platform/mediq/packages/full-stack/node/build/index.js:97:10

Please try to answer the following questions:

// .neutrinorc.js 9.0.0-rc.0
module.exports = {
  options: {
    root: __dirname,
  },
  use: [
    '@neutrinojs/airbnb-base',
    [
      '@neutrinojs/library',
      {
        name: 'full-stack-node',
        target: 'node',
        libraryTarget: 'commonjs2',
      }
    ],
    '@neutrinojs/jest'
  ]
};
// .neutrinorc.js 9.0.0-rc.1
const airbnbBase = require('@neutrinojs/airbnb-base');
const library = require('@neutrinojs/library');
const jest = require('@neutrinojs/jest');

module.exports = {
  options: {
    root: __dirname,
  },
  use: [
    airbnbBase(),
    library({
      name: 'full-stack-node',
        target: 'node',
        libraryTarget: 'commonjs2',
    }),
    jest(),
  ],
};
eliperelman commented 5 years ago

Can you share any of the application code? I am wondering what functionality you may be using that may need to be polyfilled. According to the docs for library:

Important! This preset does not include @babel/polyfill for size reasons. If you need polyfills in your library code, consider importing @babel/polyfill, core-js, or other alternative.

Tassfighter commented 5 years ago

I am using neutrino together with lerna in a monorepo. My library is just a little boilerplate to create web servers with hapi.

import fs from 'fs';
import Hapi from 'hapi';
import pino from 'hapi-pino';
import Inert from 'inert';
import Vision from 'vision';
import HapiSwagger from 'hapi-swagger';
import Pack from '../../package';

import systemRoutes from './routes'; // tiny hello world route

const prettyPrint = true; // process.env.NODE_ENV !== 'production';
const logger = require('pino')({ prettyPrint });

// TODO: enable TLS by removing the following line
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

const {
  HOST, PORT, TLS_KEY, TLS_CERT, CORS,
} = process.env;

function buildContext() {
  const context = {
    host: HOST || '0.0.0.0',
    port: PORT || 6781,
    routes: {
      cors: String(CORS) !== 'false',
    },
  };

  if (TLS_KEY && TLS_CERT) {
    const tls = {
      key: fs.readFileSync(TLS_KEY),
      cert: fs.readFileSync(TLS_CERT),
    };
    return { ...context, ...tls };
  }

  return context;
}

class Server {
  constructor({ context, routes, info }) {
    this.info = info;

    this.context = { ...buildContext(), ...(context || {}) };
    this.server = Hapi.server(this.context);

    logger.info(systemRoutes, routes);
    this.routes = systemRoutes;
    if (routes && routes.length > 0) {
      this.routes = [...systemRoutes, ...routes];
    }
    logger.info(this.routes);
    this.server.route(this.routes);
  }

  async start() {
    try {
      await this.server.register([
        Inert,
        Vision,
        {
          plugin: HapiSwagger,
          options: {
            info: this.info || {
              title: 'API Documentation',
              version: Pack.version,
            },
          },
        },
        {
          plugin: pino,
          options: {
            prettyPrint,
            // Redact Authorization headers, see https://getpino.io/#/docs/redaction
            redact: ['req.headers.authorization'],
          },
        },
      ]);

      await this.server.start();
    } catch (err) {
      logger.fatal(err);
      process.exit(1);
    }
  }
}

export default Server;
Tassfighter commented 5 years ago

This is how I use the library.

import Node from 'full-stack-node';

const routes = [];

const context = {
  port: process.env.PORT || 8200,
};

const server = new Node.Server({ context, routes });

server.start();
Tassfighter commented 5 years ago

Seems like this is the same error: 1417

So the issue is in neutrino's library preset and react-component preset. Some how they cannot handle async/await.

Tassfighter commented 5 years ago

@eliperelman Thanks! Finally I got it...

import "core-js/stable";
import "regenerator-runtime/runtime";

from babel-polyfill