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 when building with webpack #420

Closed
sunjay opened this issue May 18, 2016 · 18 comments
Closed

Error when building with webpack #420

sunjay opened this issue May 18, 2016 · 18 comments

Comments

@sunjay
Copy link

sunjay commented May 18, 2016

ERROR in ./~/@horizon/client/lib/util/fetch.js
Module not found: Error: Cannot resolve module 'exports' in ./node_modules/@horizon/client/lib/util
 @ ./~/@horizon/client/lib/util/fetch.js 13:0-69

Server Version: 1.0.1
Client Version: 1.0.1

Installed client with npm install @horizon/client

I am following the second option in the instructions for Integrating Horizon.

I'm seeing the error above. I installed @horizon/client and attempted to build it within my existing setup. Apparently this has something to do with the imports loader. Installing imports-loader in my project doesn't fix the problem.

In fetch.js:

require('imports?this=>global!exports?global.fetch!isomorphic-fetch');

That is the problem line.

My code is exactly the example on the @horizon/client npm page:

const Horizon = require("@horizon/client")
const horizon = Horizon()
@deontologician deontologician added this to the Triaging... milestone May 18, 2016
@deontologician
Copy link
Contributor

Hi @sunjay

Have you installed all dependencies of the client and the server?

@sunjay
Copy link
Author

sunjay commented May 18, 2016

That should happen automatically with npm install shouldn't it?

@deontologician
Copy link
Contributor

It should, but we haven't seen this problem before, so I'm trying to find out what might be going wrong.

@deontologician
Copy link
Contributor

Ok, I might have been confused. This is your own webpack configuration that you're using right?

@sunjay
Copy link
Author

sunjay commented May 19, 2016

@deontologician Yes. Let me give you some more detailed information.

I have a simple project setup to build with webpack.

Here is my webpack config file:

const path = require('path');

const CopyWebpackPlugin = require('copy-webpack-plugin');
const autoprefixer = require('autoprefixer');

const DIST = path.resolve(__dirname, 'dist');

module.exports = {
  entry: {
    app: './app/index.js',
  },
  devServer: {
    outputPath: DIST,
  },
  output: {
    path: DIST,
    filename: '[name].js',
    publicPath: '/',
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loaders: ['babel-loader'],
      },
      {
        test: /\.scss$/,
        loaders: ['style', 'css?modules&importLoaders=1&sourceMap!postcss!sass?sourceMap&sourceMapContents'],
      },
      {
        test: /\.json$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'json-loader',
      },
    ],
  },
  plugins: [
    new CopyWebpackPlugin([
      {from: 'app/index.html'},
    ]),
  ],
  resolve: {
    extensions: ['', '.js', '.jsx'],
  },
  devtool: 'inline-source-map',
  postcss: [autoprefixer],
};

Webpack essentially builds the application bundle, places it in the dist directory and also copies a simple index.html file to the same directory. These are both then to be served by Horizon.

My app/index.js file is very simple too:

const Horizon = require("@horizon/client")
const horizon = Horizon()

horizon.onReady(() => {
  document.querySelector('h1').innerHTML = 'api works!'
});
horizon.connect();

I copied this code from the index.html file generated and used the require() from the docs I linked to above.

The problem is that when I run my webpack build, I get this error:

ERROR in ./~/@horizon/client/lib/util/fetch.js
Module not found: Error: Cannot resolve module 'exports' in ./node_modules/@horizon/client/lib/util
 @ ./~/@horizon/client/lib/util/fetch.js 13:0-69

This error is not in my code. It has to do with a line in fetch.js which is using the webpack imports-loader package.

This is a bug because I can't build using require('@horizon/client') due to this error.

@sachinbhutani
Copy link

I get a similar error with webpack, but mine reads "imports" instead of "exports"
it was working with version 0.3.2
now i am on version horizon v1.0.1
ERROR in .//@horizon/client/lib/util/fetch.js
Module not found: Error: Cannot resolve module 'imports' in /Users/sachin/sites/node/h7/node_modules/@horizon/client/lib/util
@ ./
/@horizon/client/lib/util/fetch.js 13:0-69

My webpack config is even simpler
{
"name": "H7",
"version": "0.0.1",
"description": "Horizon VueJs Webpack Starter",
"dependencies": {
"vue": "^1.0.24",
"@horizon/client": "^1.0.1"
},
"devDependencies": {
"babel-core": "^6.1.2",
"babel-loader": "^6.1.0",
"babel-plugin-transform-runtime": "^6.1.2",
"babel-preset-es2015": "^6.1.2",
"babel-preset-stage-0": "^6.1.2",
"babel-runtime": "^5.8.0",
"webpack": "^1.13.0",
"css-loader": "^0.23.0",
"style-loader": "^0.13.0",
"vue-loader": "^7.3.0",
"vue-html-loader": "^1.0.0",
"vue-hot-reload-api": "^1.2.0"
},
"scripts": {
"dev": "hz serve --dev & webpack-dev-server --inline --hot"
},
"author": "Sachin"
}

@flipace
Copy link
Contributor

flipace commented May 19, 2016

I also ran into this. It was my mistake - we have to add import/exports
loader not to devDependencies but dependencies. I can create a pr later.

A solution for now is to install exports-loader and imports-loader manually
in the project where horizon is used.

EDIT: here #437

@hnordt
Copy link
Contributor

hnordt commented May 20, 2016

Same problem here using webpack:

ERROR in ./~/@horizon/client/lib/util/fetch.js
Module not found: Error: Cannot resolve module 'imports' in /Users/hnordt/workspace/healthware_app/node_modules/@horizon/client/lib/util
 @ ./~/@horizon/client/lib/util/fetch.js 13:0-69

@haukurk
Copy link

haukurk commented May 25, 2016

+1

@stellanhaglund
Copy link

I have the same error and I'm not using webpack, I just tried to import it from node.

Installing the dependencies doesn't fix it only commenting out the

require('imports?this=>global!exports?global.fetch!isomorphic-fetch');

@deontologician
Copy link
Contributor

If you're using node, import the version from @horizon/client/dist/horizon since that's compiled already.

@stellanhaglund
Copy link

When i do, it doesnt seem to connect or anything.

fredag 27 maj 2016 skrev Josh Kuhn notifications@github.com:

If you're using node, import the version from @horizon/client/dist/horizon
since that's compiled already.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#420 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ACZ_rpKP7k7h4OpesJU40RhWqnMq1S0Eks5qFwS2gaJpZM4IhvB7
.

@sunjay
Copy link
Author

sunjay commented Jun 5, 2016

@deontologician Has this fix been released?

@deontologician
Copy link
Contributor

not yet

On Sat, Jun 4, 2016, 21:50 Sunjay Varma notifications@github.com wrote:

@deontologician https://github.com/deontologician Has this fix been
released?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#420 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAAFVk-EcN5mW4EEXT8HkF6ELRNvonf0ks5qIlV3gaJpZM4IhvB7
.

deontologician pushed a commit that referenced this issue Jun 15, 2016
…#477, #420) (#593)

* remove isomorphic-fetch and imports/exports loaders, use whatwg-fetch, replace webpack specific syntax in fetch.js and move it to webpack config

* remove deprecated loaders

* Revert "remove deprecated loaders"

This reverts commit 90bc2d0.
deontologician pushed a commit that referenced this issue Jun 16, 2016
…#477, #420) (#593)

* remove isomorphic-fetch and imports/exports loaders, use whatwg-fetch, replace webpack specific syntax in fetch.js and move it to webpack config

* remove deprecated loaders

* Revert "remove deprecated loaders"

This reverts commit 90bc2d0.
@deontologician deontologician modified the milestones: Closed with no code written, Triaging... Jul 8, 2016
@StefanSchwartze
Copy link

What is the current status? I still can't use horizon client because of this bug..

@deontologician
Copy link
Contributor

Try the version on the next branch in github. We've removed the fetch
dependency

On Sun, Jul 17, 2016, 14:09 StefanSchwartze notifications@github.com
wrote:

What is the current status? I still can't use horizon client because of
this bug..


You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub
#420 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAFVt3ZY7Yrk40DLVDlnRXhyj-5t8K6ks5qWpohgaJpZM4IhvB7
.

@StefanSchwartze
Copy link

How can I install that version? npm install @horizon/client@2.0.0 and git+ssh://git@github.com:rethinkdb/horizon.git#2.0.0 didn't work for me..

@deontologician
Copy link
Contributor

we havent tagged 2.0 yet, you'll probably need to check it out and build it
yourself

On Sun, Jul 17, 2016, 17:05 StefanSchwartze notifications@github.com
wrote:

How can I install that version? npm install @horizon/client@2.0.0 and
git+ssh://git@github.com:rethinkdb/horizon.git#2.0.0 didn't work for me..


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#420 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAFVsnHc8MRDuB4jbLV0VT2f30QmOcWks5qWsNkgaJpZM4IhvB7
.

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

8 participants