question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when importing Pouchdb

See original GitHub issue

Hello, I’m trying to use Pouchdb with this boilerplate, however, whenever I add import PouchDB from 'pouchdb'; anywhere, I immediately get the following error:

WARNING in ./~/levelup/lib/util.js [0] Module not found: Error: Cannot resolve module 'leveldown/package' in /home/samir/Sites/school/node_modules/levelup/lib [0] @ ./~/levelup/lib/util.js 36:23-51 [0] [0] WARNING in ./~/bindings/bindings.js [0] Critical dependencies: [0] 76:22-40 the request of a dependency is an expression [0] 76:43-53 the request of a dependency is an expression [0] @ ./~/bindings/bindings.js 76:22-40 76:43-53 [0] [0] WARNING in ./~/bindings/README.md [0] Module parse failed: /home/samir/Sites/school/node_modules/bindings/README.md Unexpected token (2:3) [0] You may need an appropriate loader to handle this file type. [0] SyntaxError: Unexpected token (2:3) [0] at Parser.pp.raise (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:923:13) [0] at Parser.pp.unexpected (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:1490:8) [0] at Parser.pp.parseExprAtom (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:333:12) [0] at Parser.pp.parseExprSubscripts (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:228:19) [0] at Parser.pp.parseMaybeUnary (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:207:17) [0] at Parser.pp.parseExprOp (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:174:41) [0] at Parser.pp.parseExprOp (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:176:19) [0] at Parser.pp.parseExprOps (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:156:15) [0] at Parser.pp.parseMaybeConditional (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:136:19) [0] at Parser.pp.parseMaybeAssign (/home/samir/Sites/school/node_modules/webpack/node_modules/acorn/dist/acorn.js:112:19) [0] @ ./~/bindings ^\.\/.*$

And the app devtools shows the following: validate.js?c7dd:17Uncaught Error: define cannot be used indirect

After a long search I stumbled on the following https://github.com/pouchdb/pouchdb/issues/3647 but unfortunately the suggested solution does not work for me.

How do I fix this? I’m pretty much useless when it comes to Webpack, hence the question. Thank you, and good evening

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Unforgiven-wandacommented, Jun 16, 2016

Hello again, Tried your approach, I’m still encoutering the same error: validate.js?c7dd:17Uncaught Error: define cannot be used indirect

The terminal however shows a clean bundle this time.

My webpack.config.base.js

import path from 'path';

export default {
  module: {
    loaders: [{
      test: /\.jsx?$/,
      loaders: ['babel-loader'],
      exclude: /node_modules/
    }, {
      test: /\.json$/,
      loader: 'json-loader'
    }]
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    libraryTarget: 'commonjs2'
  },
  resolve: {
    extensions: ['', '.js', '.jsx', '.json'],
    packageMains: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main']
  },
  plugins: [

  ],
  externals: [
    // put your node 3rd party libraries which can't be built with webpack here
    // (mysql, mongodb, and so on..)
    'leveldown'
  ]
};

Edit: After more trial and error, It seems to be fixed. I just added this line to your solution: noParse: /node_modules\/json-schema\/lib\/validate\.js/

Resulting in this final webpack.config.base.js file :

import path from 'path';

export default {
  module: {
    loaders: [{
      test: /\.jsx?$/,
      loaders: ['babel-loader'],
      exclude: /node_modules/
    }, {
      test: /\.json$/,
      loader: 'json-loader'
    }],
    noParse: /node_modules\/json-schema\/lib\/validate\.js/
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    libraryTarget: 'commonjs2'
  },
  resolve: {
    extensions: ['', '.js', '.jsx', '.json'],
    packageMains: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main']
  },
  plugins: [

  ],
  externals: [
    // put your node 3rd party libraries which can't be built with webpack here
    // (mysql, mongodb, and so on..)
    'leveldown'
  ]
};

1reaction
dmrcommented, Jun 29, 2016

Thank you for sharing this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to import pouchdb in angular4 · Issue #6672 - GitHub
ERROR in C:/Users/aallawati/Development/pro1/src/app/dbtool.service.ts (3,21): Cannot find module 'pouchdb-browser'. webpack: Failed to compile.
Read more >
Can't use pouchdb with Typescript ? Types problem?
ts(3,8): error TS1192: Module '"C:/Users/User/PROG/toto/node_modules/@types/pouchdb/index"' has no default export. I tried import * as Pouchdb ...
Read more >
Common Errors - PouchDB
Reading from/writing to a local database from an iframe with a different origin will cause PouchDB to throw a No valid adapter found...
Read more >
Update docs · usePouchDB
Todo.js import React from 'react' import { usePouch } from 'use-pouchdb' export default function ... else { console.error(err) // Handle other errors. } ......
Read more >
Pouchdb doesn't work? - Ionic Framework
When I try to use it (import Pouchdb from 'pouchdb'), I get this error. ERROR in src/app/services/pouchdb.service.ts(3,8): error TS1192: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found