Has anyone run into `pino` is not a function error...
# pact-js
x
Has anyone run into
pino
is not a function error? TypeError: pino is not a function
Copy code
at Object.createLogger(../../node_modules/@pact-foundation/pact-core/src/logger/pino.ts
at Object.createLogger(../../node_modules/@pact-foundation/pact-core/src/logger/index.ts
at Object.createLogger(../../node_modules/@pact-foundation/pact-core/src/service.ts
I got this error when I tried to do
Copy code
const provider = new PactV3({consumer:"foo",provider:"bar"});
t
what version?
x
Copy code
jest: 28.1.3
@pact-foundation/pact: 10.1.3
typescript: 4.8.2
ts-jest:28.0.8
@types/jest: 28.1.3
m
I've seen it with an old version of create react app which bundles an old version of babel
(or at least, similar errors where it can't transpile newer modules)
x
this is a pure node project
and it uses typescript only and no babel
m
Strange
x
any jest and ts config can cause this?
m
I'm not sure sorry
If you could share a repro project and raise an issue we could take a look
x
ok , i will give it a try to see if i can reproduce that with a brand new project
thank you
m
👍
t
This part is suspicious -
../../
- are you installing your node_modules somewhere custom? Are you running your tests from a non-root directory?
Can you share your tsconfig?
Also that error is very suspicious - it's naming the .ts files, but it should be running the JS files 😕
x
Copy code
folder structure

my-project
 -node_modules
 -src
   -__tests__
      -mytest.pact.ts
👍 1
t
what does
npm ls pino
do?
x
Copy code
module.exports = {
 roots: ['<rootDir>/src'],
 transform: {
   '^.+\\.tsx?$': 'ts-jest',
 },
 testRegex: '(/__tests__/.*|(\\.|/))\\.(test|spec|pact)\\.tsx?$',
 moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
 collectCoverage: true,
 collectCoverageFrom: ['src/**/*.ts'],
 coveragePathIgnorePatterns: ['index.ts'],
 moduleDirectories: ['node_modules', '.', '../../utils'],
 coverageThreshold: {
   global: {
     statements: 80,
   },
 },
};
tsconfig
Copy code
{
  "compilerOptions": {
    "baseUrl": "./",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "./dist",
    "allowJs": false,
    "declaration": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "target": "es2018",
    "lib": [
      "es2018",
      "esnext.asynciterable"
    ],
    "sourceMap": true,
    "strict": true,
    "strictNullChecks": false,
    "paths": {
      "src/*": [
        "src/*"
      ]
    }
  },
  "exclude": [
    "node_modules"
  ],
  "include": [
    "src",
    "*.d.ts",
    "mocks"
  ]
}
t
moduleDirectories: ['node_modules'
<-- node_modules definitely should not be here
'../../utils'
<-- this is also suspicious, since it suggests there's a package above you
x
this project lives in a monorepo (yarn workspace)
t
1) The monorepo isn't in your folder structure diagram :P 2) I was wrong about moduleDirectories (the documentation is here). However, this is still your problem - you're loading ts files before js files. Don't do that.
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
<-- change this
moduleFileExtensions: [ 'js', 'jsx', 'ts', 'tsx','json', 'node'],
<-- to this
You're currently asking ts-jest to transpile node_modules which is definitely wrong
so the require is failing because your tsconfig has different settings to the one that pact was compiled with
This is a jest config problem, not a pact problem. I'm surprised only pact broke
@Matt (pactflow.io / pact-js / pact-go) Pact could prevent this mistake from being a problem by not including the .ts files in the bundle
x
yea, this project has other jest tests e.g some ajv validation stuff that work just fine
t
(you'd have to make sure the
.d.ts
files are still included of course)
Sure. However, the problem is in the jest config, which is being asked to transpile node_modules, which you are not supposed to do.
x
when i tried to remove that node_modules from it then it starts to complain about
cannot-find-module-source-map-support
(probably i can take look at this ) .
t
ajv
avoids this problem by putting the compiled files in a
dist
folder, so imports don't get confused
Yes, as I said above, I was wrong about removing node_modules
but you need to correct
moduleFileExtensions
x
i did but that doesnt not seem to fix it
same error
t
I don't know, sorry. I suspect there's something going on with your monorepo setup - maybe a config file from the root repo is overriding something?
this isn't a pact problem, it's a jest/typescript config problem
you can tell because the error message is talking about typescript files inside pact.
x
okay, anyway, i appreciate for all your help, i will dig a little bit into it to see if i have any luck😆
👍 1
surprisingly , the old version works
@pack-foundation/pact v9.18
nothing changes in terms of my config
t
I think 9.18 didn't use pino but I don't remember
😧 1
Update: I checked, not only did it still use Pino, but it still used that specific import line. I suspect yarn monorepo weirdness
🙏 1
x
mystery solved: for the jest config , we included
"."
in the moduleDirectories field and that causes the pino failure
it seems to be a bug that cause by the co-existence of
module-alias
and the pact package
t
I explained above, the problem is that you're transpiling node_modules when you shouldn't be. You can tell because the error is coming from typescript files, which should not be what you are running.
So the package combinations will just change whether or not you see an error, not fix the problem (which as I have already told you, is that you're transpiling node_modules). My current guess is that
node_modules
is by default blocked from being involved in the transpilation, but reincluded when you include
"."
in the modules. Anyway, this isn't a pact problem. It is a problem to do with the strange way that ts-jest is set up in this project.
👍 1