fn is not a function

See original GitHub issue

I’ve simple test that is as follows

// abc.test.ts
const Client = require('node-rest-client').Client;
import Nightmare from "nightmare";
import * as chai from "chai";
import chaiString from "chai-string";
chai.use(chaiString);  
//node_modules\chai\lib\chai.js:39
//    fn(exports, util);
//   ^
// TypeError: fn is not a function

The npm command is as follows mocha --recursive --require jsdom-global/register --require ts-node/register --require babel-core/register tests/domains/*

Issue Analytics

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

github_iconTop GitHub Comments

23reactions
basherrcommented, Jan 9, 2018

closing as chai works with require statement.

10reactions
meebercommented, Feb 10, 2018

@gary1410 It’s difficult to troubleshoot OP’s issue because they’re using a couple of transpilers. What I can tell you is that “TypeError: fn is not a function” is saying that the value being passed to chai.use() isn’t a function, suggesting that the problem is related to import chaiString from "chai-string"; (as opposed to the Chai import). However, the below example (with no transpilers) works fine for me when running node --experimental-modules with Chai@4.1.2, so I dunno. I’d guess OP’s issue is related to transpiling.

import chai from "chai";
import chaiString from "chai-string";

chai.use(chaiString);

chai.expect("blah").to.startWith("bl"); // Passes
chai.expect("blah").to.startWith("xl"); // Throws AssertionError
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve "TypeError: fn is not a function"? - Stack Overflow
TypeError : fn is not a function. in this code block of my application const utils = require('./utils') const strategies = require('.
Read more >
Type error: fn is not a function. I don't know how to fix that.. Any ...
I've been trying to code a Discord bot to do a Timed mute, but there seems to be an error which I don't...
Read more >
TypeError: fn is not a function · Discussion #5548 - GitHub
When I execute the following Javascript test script it returns with TypeError: fn is not a function. Here´s the .js code. async function...
Read more >
How to Handle JavaScript Uncaught TypeError: “x” is Not a ...
The Javascript error TypeError: "x" is not a function occurs when there is an attempt to call a function on a value or...
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
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