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

Webpack usage #17

Closed
vladshcherbin opened this issue Jan 16, 2017 · 17 comments
Closed

Webpack usage #17

vladshcherbin opened this issue Jan 16, 2017 · 17 comments
Labels
external Issues with dependencies or otherwise unsolvable within the project itself. question Not a true issue, usually a question relating to usage.

Comments

@vladshcherbin
Copy link

Hey, where is trilogy supposed to be used, in main or in renderer?
I tried it in renderer, but webpack gives me errors.

@haltcase
Copy link
Owner

@vladshcherbin it should work in both, although I haven't used it with Webpack. It's likely due to sqlite3 and the way all the bundling + native modules work, and your external dependency setup.

It'd help if you posted the errors you were receiving.

@haltcase haltcase added the status: need response Waiting for more information from the issue author. label Jan 16, 2017
@vladshcherbin
Copy link
Author

Yeah, I'm trying to figure out the correct usage. So, I'm installing trilogy & sqlite3. The app is running locally.

app.js

import React from 'react'
import ReactDOM from 'react-dom'
import Trilogy from 'trilogy'

ReactDOM.render(
  <p>h2</p>,
  document.getElementById('app')
)

The errors are:

errors
WARNING in ./~/sqlite3/~/node-pre-gyp/lib/util/compile.js
Module not found: Error: Can't resolve 'npm' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/sqlite3/node_modules/node-pre-gyp/lib/util'
 @ ./~/sqlite3/~/node-pre-gyp/lib/util/compile.js 39:27-49
 @ ./~/sqlite3/~/node-pre-gyp/lib ^\.\/.*$
 @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js
 @ ./~/sqlite3/lib/sqlite3.js
 @ ./~/knex/lib/dialects/sqlite3/index.js
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

WARNING in ./~/sqlite3/~/node-pre-gyp/lib/util/nw-pre-gyp/index.html
Module parse failed: /Users/shcherbin/Sites/projects/sketch-plugins/node_modules/sqlite3/node_modules/node-pre-gyp/lib/util/nw-pre-gyp/index.html Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <!doctype html>
| <html>
| <head>
 @ ./~/sqlite3/~/node-pre-gyp/lib ^\.\/.*$
 @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js
 @ ./~/sqlite3/lib/sqlite3.js
 @ ./~/knex/lib/dialects/sqlite3/index.js
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

WARNING in ./~/knex/lib/migrate/index.js
339:20-81 Critical dependency: the request of a dependency is an expression

WARNING in ./~/knex/lib/migrate/index.js
444:18-49 Critical dependency: the request of a dependency is an expression

WARNING in ./~/knex/lib/seed/index.js
113:13-74 Critical dependency: the request of a dependency is an expression

WARNING in ./~/knex/lib/seed/index.js
150:11-24 Critical dependency: the request of a dependency is an expression

WARNING in ./~/sqlite3/lib/sqlite3.js
4:14-35 Critical dependency: the request of a dependency is an expression

WARNING in ./~/sqlite3/~/node-pre-gyp/lib/pre-binding.js
19:22-48 Critical dependency: the request of a dependency is an expression

WARNING in ./~/sqlite3/~/node-pre-gyp/lib/util/versioning.js
15:20-67 Critical dependency: the request of a dependency is an expression

ERROR in ./~/trilogy/dist/trilogy.mjs
Module not found: Error: Can't resolve 'sql.js' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/trilogy/dist'
 @ ./~/trilogy/dist/trilogy.mjs 7:0-25
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/mysql/index.js
Module not found: Error: Can't resolve 'mysql' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/mysql'
 @ ./~/knex/lib/dialects/mysql/index.js 73:11-27
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/mssql/index.js
Module not found: Error: Can't resolve 'mssql' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/mssql'
 @ ./~/knex/lib/dialects/mssql/index.js 104:11-27
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/maria/index.js
Module not found: Error: Can't resolve 'mariasql' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/maria'
 @ ./~/knex/lib/dialects/maria/index.js 59:11-30
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/oracle/index.js
Module not found: Error: Can't resolve 'oracle' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/oracle'
 @ ./~/knex/lib/dialects/oracle/index.js 97:11-28
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/postgres/index.js
Module not found: Error: Can't resolve 'pg' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/postgres'
 @ ./~/knex/lib/dialects/postgres/index.js 87:11-24
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/postgres/index.js
Module not found: Error: Can't resolve 'pg-query-stream' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/postgres'
 @ ./~/knex/lib/dialects/postgres/index.js 210:54-80
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/mysql2/index.js
Module not found: Error: Can't resolve 'mysql2' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/mysql2'
 @ ./~/knex/lib/dialects/mysql2/index.js 63:11-28
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/oracledb/index.js
Module not found: Error: Can't resolve 'oracledb' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/oracledb'
 @ ./~/knex/lib/dialects/oracledb/index.js 45:17-36 320:17-36
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/strong-oracle/index.js
Module not found: Error: Can't resolve 'strong-oracle' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/strong-oracle'
 @ ./~/knex/lib/dialects/strong-oracle/index.js 23:9-33
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/sqlite3/~/node-pre-gyp/lib/info.js
Module not found: Error: Can't resolve 'aws-sdk' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/sqlite3/node_modules/node-pre-gyp/lib'
 @ ./~/sqlite3/~/node-pre-gyp/lib/info.js 14:14-32
 @ ./~/sqlite3/~/node-pre-gyp/lib ^\.\/.*$
 @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js
 @ ./~/sqlite3/lib/sqlite3.js
 @ ./~/knex/lib/dialects/sqlite3/index.js
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/sqlite3/~/node-pre-gyp/lib/publish.js
Module not found: Error: Can't resolve 'aws-sdk' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/sqlite3/node_modules/node-pre-gyp/lib'
 @ ./~/sqlite3/~/node-pre-gyp/lib/publish.js 17:14-32
 @ ./~/sqlite3/~/node-pre-gyp/lib ^\.\/.*$
 @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js
 @ ./~/sqlite3/lib/sqlite3.js
 @ ./~/knex/lib/dialects/sqlite3/index.js
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/sqlite3/~/node-pre-gyp/lib/unpublish.js
Module not found: Error: Can't resolve 'aws-sdk' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/sqlite3/node_modules/node-pre-gyp/lib'
 @ ./~/sqlite3/~/node-pre-gyp/lib/unpublish.js 15:14-32
 @ ./~/sqlite3/~/node-pre-gyp/lib ^\.\/.*$
 @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js
 @ ./~/sqlite3/lib/sqlite3.js
 @ ./~/knex/lib/dialects/sqlite3/index.js
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/sqlite3/~/node-pre-gyp/~/rc/index.js
Module parse failed: /Users/shcherbin/Sites/projects/sketch-plugins/node_modules/sqlite3/node_modules/node-pre-gyp/node_modules/rc/index.js Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| #! /usr/bin/env node
| var cc   = require('./lib/utils')
| var join = require('path').join
 @ ./~/sqlite3/~/node-pre-gyp/lib/info.js 11:13-26
 @ ./~/sqlite3/~/node-pre-gyp/lib ^\.\/.*$
 @ ./~/sqlite3/~/node-pre-gyp/lib/node-pre-gyp.js
 @ ./~/sqlite3/lib/sqlite3.js
 @ ./~/knex/lib/dialects/sqlite3/index.js
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

@vladshcherbin
Copy link
Author

I can compile with no errors if I use externals in webpack:

externals: [
  'sqlite3',
  'knex',
  'trilogy'
]

But if I'm not mistaken, none of this modules will be bundled in the app.

@haltcase
Copy link
Owner

I'd suggest either adding Trilogy and sqlite3 to your externals or using sql.js as your backend.

Is this for a deployed client-side app or something in Electron / nw.js?

@vladshcherbin
Copy link
Author

I'm trying to use it with an Electron app.

@haltcase
Copy link
Owner

haltcase commented Jan 16, 2017

Yep, they won't be bundled if you specify them as externals. But it's not possible to bundle sqlite3 at all since it's a native C binding. See TryGhost/node-sqlite3#698.

sql.js might bundle however I haven't tried it. It's a pure JS alternative and I'd think it would work fairly smoothly. You can do this by passing client: 'sql.js' in the options object to new Trilogy().

All that said, if you're making an Electron app bundling isn't strictly necessary. It can help with optimization, sure, but isn't the biggest bottleneck you'll face. A few externals is to be expected.

fyi: I updated the title since this is related more to Webpack than to Trilogy / Electron renderer, but let me know if you feel that's not accurate

@haltcase haltcase added external Issues with dependencies or otherwise unsolvable within the project itself. question Not a true issue, usually a question relating to usage. and removed status: need response Waiting for more information from the issue author. labels Jan 16, 2017
@haltcase haltcase changed the title Renderer usage Webpack usage Jan 16, 2017
@vladshcherbin
Copy link
Author

Yes, sql.js may be an option.

The main question is - how do you use it in renderer if it's not bundled? Do you specify all methods in main and then use .remote or another thing to call methods from renderer or smth else?

@haltcase
Copy link
Owner

haltcase commented Jan 16, 2017

It should work the same in renderer as it does in main since renderer is basically the usual webpage extended with node, so just require it. The only real caveat is you have to instantiate Trilogy in each since they're separate processes.

@vladshcherbin
Copy link
Author

Okay, I put sqlite3 and knex in externals.

externals: [
  'sqlite3',
  'knex'
]

Still have an error:

ERROR in ./~/trilogy/dist/trilogy.mjs
Module not found: Error: Can't resolve 'sql.js' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/trilogy/dist'
 @ ./~/trilogy/dist/trilogy.mjs 7:0-25
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

@vladshcherbin
Copy link
Author

If I use bare electron, even w/o webpack:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <p>hey</p>
    <script>
      const Trilogy = require('trilogy')
    </script>
  </body>
</html>

I also see this error in console:

Uncaught Error: Cannot find module 'sql.js'

@haltcase
Copy link
Owner

haltcase commented Jan 16, 2017

Ah I see an issue there - if you're not using sql.js I shouldn't import it. That'll need to be fixed. In the interest of not holding back your development, what if you install sql.js or use sql.js as your backend? You'll always be able to switch back without changing your code so you wouldn't be locked in.

I've opened a new issue (see below) for this since it's sort of a tangent from the original topic of 'webpack'.

@vladshcherbin
Copy link
Author

Sure, I'll try to use sql.js for now.

@vladshcherbin
Copy link
Author

vladshcherbin commented Jan 16, 2017

Hm, I changed sqlite3 to sql.js and updated externals:

externals: [
  'knex'
]

As a result, there are no more sqlite errors as expected. Webpack bundles with no errors. Unfortunately, when I import trilogy - I see an error in the console:

Uncaught ReferenceError: knex is not defined

If I remove knex from externals, I see errors in webpack:

errors
WARNING in ./~/knex/lib/migrate/index.js
339:20-81 Critical dependency: the request of a dependency is an expression

WARNING in ./~/knex/lib/migrate/index.js
444:18-49 Critical dependency: the request of a dependency is an expression

WARNING in ./~/knex/lib/seed/index.js
113:13-74 Critical dependency: the request of a dependency is an expression

WARNING in ./~/knex/lib/seed/index.js
150:11-24 Critical dependency: the request of a dependency is an expression

ERROR in ./~/knex/lib/dialects/sqlite3/index.js
Module not found: Error: Can't resolve 'sqlite3' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/sqlite3'
 @ ./~/knex/lib/dialects/sqlite3/index.js 75:11-29
 @ ./~/knex/lib/dialects/websql/index.js
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/maria/index.js
Module not found: Error: Can't resolve 'mariasql' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/maria'
 @ ./~/knex/lib/dialects/maria/index.js 59:11-30
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/mysql/index.js
Module not found: Error: Can't resolve 'mysql' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/mysql'
 @ ./~/knex/lib/dialects/mysql/index.js 73:11-27
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/mssql/index.js
Module not found: Error: Can't resolve 'mssql' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/mssql'
 @ ./~/knex/lib/dialects/mssql/index.js 104:11-27
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/mysql2/index.js
Module not found: Error: Can't resolve 'mysql2' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/mysql2'
 @ ./~/knex/lib/dialects/mysql2/index.js 63:11-28
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/oracle/index.js
Module not found: Error: Can't resolve 'oracle' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/oracle'
 @ ./~/knex/lib/dialects/oracle/index.js 97:11-28
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/oracledb/index.js
Module not found: Error: Can't resolve 'oracledb' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/oracledb'
 @ ./~/knex/lib/dialects/oracledb/index.js 45:17-36 320:17-36
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/postgres/index.js
Module not found: Error: Can't resolve 'pg' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/postgres'
 @ ./~/knex/lib/dialects/postgres/index.js 87:11-24
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/postgres/index.js
Module not found: Error: Can't resolve 'pg-query-stream' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/postgres'
 @ ./~/knex/lib/dialects/postgres/index.js 210:54-80
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

ERROR in ./~/knex/lib/dialects/strong-oracle/index.js
Module not found: Error: Can't resolve 'strong-oracle' in '/Users/shcherbin/Sites/projects/sketch-plugins/node_modules/knex/lib/dialects/strong-oracle'
 @ ./~/knex/lib/dialects/strong-oracle/index.js 23:9-33
 @ ./~/knex/lib/dialects ^\.\/.*\/index\.js$
 @ ./~/knex/lib/index.js
 @ ./~/knex/knex.js
 @ ./~/trilogy/dist/trilogy.mjs
 @ ./app/app.js
 @ multi babel-regenerator-runtime ./app/app.js

If I don't use webpack, I don't have any errors:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <p>hey</p>
    <script>
      const Trilogy = require('trilogy')
    </script>
  </body>
</html>

Not sure what to try now 😔

@haltcase
Copy link
Owner

haltcase commented Jan 16, 2017

All the Webpack errors from knex are because it statically analyzes every import or require statement within your bundled dependencies whether they're used or not. And since you have none of them installed ( because why would you ) they can't be resolved. There are also some that are dynamic requires ( like require(variable) ) so Webpack can't statically analyze that. Seems common by the way.

As for the knex is not defined I think it's because setting it as an external means it won't bundle it but you didn't specify Trilogy as an external as well. So Webpack is basically bundling Trilogy but ignoring its knex dependency.

@vladshcherbin
Copy link
Author

Okay, probably I don't understand what I should bundle for Electron and what I should not. With web apps I bundle all modules that I want to use on the client. So, if I want to use trilogy on the client - I bundle it.

What's about electron, why can I use this:

externals: [
  'knex',
  'trilogy',
  'react',
  'react-dom'
]

// app.js
import React from 'react'
import ReactDOM from 'react-dom'
import Trilogy from 'trilogy'

ReactDOM.render(
  <p>h2</p>,
  document.getElementById('app')
)

and still be able to import it and use in renderer ?

@haltcase
Copy link
Owner

haltcase commented Jan 16, 2017

You're thinking of Electron as a client / server relationship, which is close and is a sometimes useful comparison. But it's really more cohesive than that. The renderer can require things just like main can.

This Electron doc ( and others in the repo about usage ) may help you: Synopsis. This is why it's not as common to use Webpack / Rollup / bundles with Electron apps.

I'm going to close this since its external, but thanks for uncovering the other problem!

@vladshcherbin
Copy link
Author

@citycide thank you a lot for help 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Issues with dependencies or otherwise unsolvable within the project itself. question Not a true issue, usually a question relating to usage.
Projects
None yet
Development

No branches or pull requests

2 participants