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

Uncaught TypeError: axiosCookieJarSupport is not a function #264

Open
qxygene opened this issue Apr 14, 2021 · 12 comments
Open

Uncaught TypeError: axiosCookieJarSupport is not a function #264

qxygene opened this issue Apr 14, 2021 · 12 comments

Comments

@qxygene
Copy link

qxygene commented Apr 14, 2021

Uncaught TypeError: axiosCookieJarSupport is not a function
at Object.eval (nano.js?e764:19)

nano.js
const axiosCookieJarSupport = require('axios-cookiejar-support').default
axiosCookieJarSupport(axios)

What is wrong with this?

@SanSiren
Copy link

I get the same error. I try to connect to the database like it says in your documentation:
const nano = require('nano')('http://localhost:5984')
but get the error mentioned above.

image

@kwesimanny
Copy link

I get this too... Anything related to webpack?

@glynnbird
Copy link
Contributor

Couldn't reproduce myself:

const nano = require('nano')({
  url: process.env.COUCH_URL,
  requestDefaults: {
    jar: true
  }
})
const username = 'myusername'
const userpass = 'mypassword'
const db = nano.db.use('people')

const main = async () => {
  // authenticate
  await nano.auth(username, userpass)
  const r = await db.list({ limit: 5 })
  console.log(r)
}

main()

@PlkMarudny
Copy link

The same with vite

@OliverAndersRWE
Copy link

Hi, I have the same problem in a vue application, but using only :

var nano   = require('nano')({
  'url': 'http://server:5982/'
});

nano.auth("user", "pw", function (err, body, headers) {
  if (err) {
      return console.log(err);
  }
  if (headers && headers['set-cookie']) {
      console.log(headers['set-cookie']);
      var nano   = require('nano')({
          'url':'http://server:5982/',
          'cookie': headers['set-cookie']
      })
      console.log(nano)
   
  }

Error message:
Uncaught TypeError: axiosCookieJarSupport is not a function at Object.eval (nano.js?e764:19) at eval (nano.js:1265) at Object../node_modules/nano/lib/nano.js (chunk-vendors.js:3656) at __webpack_require__ (app.js:849) at fn (app.js:151) at eval (main.js?56d7:11) at Module../src/main.js (app.js:1148) at __webpack_require__ (app.js:849) at fn (app.js:151) at Object.1 (app.js:1161)

Any help is really appreciated...

Kind Regards
Oliver

@kwesimanny
Copy link

I get the same error. I try to connect to the database like it says in your documentation: const nano = require('nano')('http://localhost:5984') but get the error mentioned above.

image

I was able to fix my by removing the .default for axios-cookiejar-support.

@fynnlyte
Copy link

fynnlyte commented Nov 19, 2021

Related: #254

In case this helps anyone:

  • In a library that directly uses nano 9.0.5 and Typescript, I don't have any issues - all tests run through. According to the package-lock.json, it resolves as:
    "nano": {
      "version": "9.0.5",
      "resolved": "https://registry.npmjs.org/nano/-/nano-9.0.5.tgz",
      "integrity": "sha512-fEAhwAdXh4hDDnC8cYJtW6D8ivOmpvFAqT90+zEuQREpRkzA/mJPcI4EKv15JUdajaqiLTXNoKK6PaRF+/06DQ==",
      "requires": {
        "@types/tough-cookie": "^4.0.0",
        "axios": "^0.21.1",
        "axios-cookiejar-support": "^1.0.1",
        "qs": "^6.9.4",
        "tough-cookie": "^4.0.0"
      },
      "dependencies": {
        "qs": {
          "version": "6.10.1",
          "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.1.tgz",
          "integrity": "sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==",
          "requires": {
            "side-channel": "^1.0.4"
          }
        }
      }
  • But when I use that package in a different javascript project, I get the following warning during the installation:
npm WARN [email protected] requires a peer of tough-cookie@>=2.3.3 but none is installed. You must install peer dependencies yourself.
  • And I get an error „Cannot find module 'tough-cookie'”. After installing tough-cookie in that project, everything works fine.

@glynnbird
Copy link
Contributor

This is a peculiar one. Must be something to do with whatever webpack does to Nano on its journey to client-side JavaScript. Does anyone have any suggestions as to what Nano can do to stop this happening? As @LyteFM states, the package works fine in "normal" circumstances.

@mariothedev
Copy link

mariothedev commented Dec 8, 2021

This error doesn't happen under "normal" circumstances as @glynnbird mentioned. However, if you are using a framework like Next.js, this error will appear if you don't place const nano = require('nano')('http://localhost:5984'); under getStaticProps or getServerSideProps.

@fynnlyte
Copy link

I my case, I think it relates to how dependencies are resolved by npm and when running npm ci --production. I got the error in a NestJS-project where I have:

  • node_modules/jsdom/node_modules/tough-cookie (version 4.0.0) with "dev": true
  • node_modules/nano/node_modules/tough-cookie (version 4.0.0) as production dependency
  • node_modules/tough-cookie itself previously resolved with "version": "2.5.0", "dev": true. (as dependency of cypress)

And after explicitly installing "tough-cookie": 4.0.0, it works and it resolves as:

  • "node_modules/@cypress/request/node_modules/tough-cookie" with "version": "2.5.0", "dev": true.
  • "node_modules/tough-cookie" with "version": "4.0.0" as production dependency

The error I got looks like the dependency was simply missing in the node_modules:

internal/modules/cjs/loader.js:905
throw err;
 ^
Error: Cannot find module 'tough-cookie'
Require stack:
 - .../node_modules/axios-cookiejar-support/lib/interceptors/request.js
 - .../node_modules/axios-cookiejar-support/lib/index.js
- .../node_modules/nano/lib/nano.js
 - /mymodule/utils/db.js
 - /mymodule/myScript.js
     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
     at Function.Module._load (internal/modules/cjs/loader.js:746:27)
     at Module.require (internal/modules/cjs/loader.js:974:19)
     at require (internal/modules/cjs/helpers.js:93:18)
     at Object.<anonymous> (.../node_modules/axios-cookiejar-support/lib/interceptors/request.js:8:43)
     at Module._compile (internal/modules/cjs/loader.js:1085:14)
     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
     at Module.load (internal/modules/cjs/loader.js:950:32)
     at Function.Module._load (internal/modules/cjs/loader.js:790:12)
     at Module.require (internal/modules/cjs/loader.js:974:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '.../node_modules/axios-cookiejar-support/lib/interceptors/request.js',
    '.../node_modules/axios-cookiejar-support/lib/index.js', 
    '.../node_modules/nano/lib/nano.js',
    '.../mymodule/utils/db.js',
    '.../mymodule/MyScript.js'
 node[5036]:   ]
 node[5036]: }

@njmaeff
Copy link

njmaeff commented Feb 10, 2022

This is the issue right here

const axiosCookieJarSupport = require('axios-cookiejar-support').default

axios-cookiejar-support version 1.0.1 as no default export for its noop function which is used in the browser.
https://github.com/3846masa/axios-cookiejar-support/blob/39c2d72ec40880cd1070d3c122f48e82f510f198/noop.js#L1-L7

@fynnlyte
Copy link

fynnlyte commented Mar 24, 2022

With current versions of NestJS, @nestjs/axios and axios-cookiejar-support, I ran into the issue again. Replacing

 const axiosCookieJarSupport = require('axios-cookiejar-support').default

with

const axiosCookieJarSupport = require('axios-cookiejar-support').wrapper

and upgrading axios-cookiejar-support to @2.04 solved it (but I'm not using cookies with CouchDB, just basic auth - this would cause other issues, as mentioned here)

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

9 participants