Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot find any-observable implementation nor global.Observable after webpack #146

Open
kykungz opened this issue May 28, 2020 · 2 comments

Comments

@kykungz
Copy link

kykungz commented May 28, 2020

This package is working fine when I was using babel-node to run it. But after bundling my project through webpack, I got this warning:

WARNING in ./node_modules/any-observable/register.js 15:14-37
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/any-observable/index.js
 @ ./node_modules/@samverschueren/stream-to-observable/index.js
 @ ./node_modules/listr/lib/task.js
 @ ./node_modules/listr/index.js
 @ ./src/index.js

Then after I ran the built bundle, with simple node dist/bundle.js, I got this error:

Error: Cannot find any-observable implementation nor global.Observable.
You must install polyfill or call require("any-observable/register") with your preferred implementation,
e.g. require("any-observable/register")('rxjs') on application load prior to any require("any-observable").

How can I get it running after webpack build?

Here is my webpack.config.js

const path = require('path')

module.exports = {
  entry: './src/index.js',
  mode: 'production',
  target: 'node',
  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
          },
        },
      },
    ],
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
}

This is my .babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "esmodules": true
        }
      }
    ]
  ]
}
@ndelangen
Copy link

Have you found a solution perhaps?

@ndelangen
Copy link

ndelangen commented Aug 25, 2021

I now have this in a module above where listr is used:

#!/usr/bin/env node
import Observable from 'zen-observable';

global.Observable = Observable;
require('any-observable/register')('global.Observable');

require('dotenv').config();
require('./main').main(process.argv.slice(2));

I tell webpack the bundle that file, and it works.

and my webpack.config.js:

const path = require('path');

module.exports = {
  mode: 'production',
  target: 'node14',
  entry: './bin-src/register.js',
  externalsPresets: { node: true },
  output: {
    path: path.resolve(__dirname, 'bin'),
  },
  optimization: {
    minimize: true,
  },
  node: {
    global: false,
  },
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants