最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Webpack sequelize, sqlite3 error cannot find module sqlite3 - Stack Overflow

programmeradmin1浏览0评论

I try to use sequelize and sqlite3 with electron and I have problems when using it with webpack. To test the projects provided in my description do npm install before

Example 1 : I tried two projects one without webpack and it works well : The sqlite3 load correctly and write the data in the database.   

npm start will launch node_modules/.bin/electron . 

It launches the index.html that uses the index.js file:

Example 2: I use webpack to pile the project because I use ES6 syntax (in the provided example the syntax is not ES6, it just to reuse the same file as in the example 1).

npm start will pile the index.js entry point and output a bundle.js file that is used by the index.html for the electron app.

When I launch the second example, the index.html that load the bundle.js file piled with webpack I have the error below:

To see the ERRRRR issss,

  • I added a console.log in the file node_modules/sequelize/lib/dialects/sqlite/connection-manager.js line 22 as specified in this link. (Electron and sequelize error: the dialect sqlite is not supported)

Unlike in the link provided which is not about using webpack with electron. The link is my Example 1 project for me everything works perfectly on the first try without doing anything more. But I tried every solution provided for my webpack example 2 but nothing works.

I do not understand why, in the basic example when just include the index.js file directly in the html it works well, but when processed by webpack and the included in the same html it doesn’t work ? Am i missing something here ?

Everything works if not piled with webpack ? WebPack let me write ES6 and split all things into one bundle but if i manually rewrite all files and use only one file it will work... So from my point of view, here it is more a webpack behave/config problem.

I try to use sequelize and sqlite3 with electron and I have problems when using it with webpack. To test the projects provided in my description do npm install before

Example 1 : I tried two projects one without webpack and it works well : The sqlite3 load correctly and write the data in the database.  https://www.dropbox./sh/yag6690rnc5l9y0/AAA0WeKvnHxhxY4qtxhHONWma?dl=0 

npm start will launch node_modules/.bin/electron . 

It launches the index.html that uses the index.js file:

Example 2: I use webpack to pile the project because I use ES6 syntax (in the provided example the syntax is not ES6, it just to reuse the same file as in the example 1). https://www.dropbox./sh/g38305knvrpdala/AAANbVBXlc-scBrzdCQTqqI7a?dl=0

npm start will pile the index.js entry point and output a bundle.js file that is used by the index.html for the electron app.

When I launch the second example, the index.html that load the bundle.js file piled with webpack I have the error below:

To see the ERRRRR issss,

  • I added a console.log in the file node_modules/sequelize/lib/dialects/sqlite/connection-manager.js line 22 as specified in this link. (Electron and sequelize error: the dialect sqlite is not supported)

Unlike in the link provided which is not about using webpack with electron. The link is my Example 1 project for me everything works perfectly on the first try without doing anything more. But I tried every solution provided for my webpack example 2 but nothing works.

I do not understand why, in the basic example when just include the index.js file directly in the html it works well, but when processed by webpack and the included in the same html it doesn’t work ? Am i missing something here ?

Everything works if not piled with webpack ? WebPack let me write ES6 and split all things into one bundle but if i manually rewrite all files and use only one file it will work... So from my point of view, here it is more a webpack behave/config problem.

Share Improve this question edited May 23, 2017 at 11:52 CommunityBot 11 silver badge asked Jan 20, 2016 at 22:39 AaleksAaleks 4,3436 gold badges34 silver badges40 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

I finally found the solution, the problem was that the node_modules folder like sqlite was bundled in the bundle.js.

The link below provide great explanation about that and explain the configuration for the backend with webpack and prevent the node_modules of being bundled when using the require directive.

http://jlongster./Backend-Apps-with-Webpack--Part-I

The code that solve my problem is :

var nodeModules = {};
fs.readdirSync('node_modules')
  .filter(function(x) {
    return ['.bin'].indexOf(x) === -1;
  })
  .forEach(function(mod) {
    nodeModules[mod] = 'monjs ' + mod;
  });

I then added nodeModules to externals config of the webpack

module.exports = {

module: {
  .....
  externals: [nodeModules]
};

It also works for me if i set externals : ["sequelize"]

发布评论

评论列表(0)

  1. 暂无评论