Node.js Error - AssertionError [ERR_ASSERTION]: pattern should not use global or sticky mode ... after reinstalling packages

Viewed 9413

I have two node.js projects running on v10.14.2. Both were working fine.

Then I deleted all packages in the package.json and reinstalled them like this:

$ npm install <package01> <package02> <package03> ...

Installation was successful. added 228 packages from 155 contributors and audited 393 packages in 11.48s found 0 vulnerabilities

When trying to run it I now get a Error message though:

$ nodemon project01

Error Message:

[nodemon] starting `node project01.js`
/home/Project01/node_modules/hoek/lib/index.js:553
    throw new Assert.AssertionError({
    ^

AssertionError [ERR_ASSERTION]: pattern should not use global or sticky mode
    at new AssertionError (internal/assert.js:269:11)
    at Object.exports.assert (/home/Project01/node_modules/hoek/lib/index.js:553:11)
    at internals.String.regex (/home/Project01/node_modules/joi/lib/types/string/index.js:122:14)
    at Object.<anonymous> (/home/Project01/helpers/routeHelpers.js:58:27)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
[nodemon] app crashed - waiting for file changes before starting...

The same for the second app:

$ npm install <package01> <package02> <package03> ...

Installation was successful. added 151 packages from 116 contributors and audited 303 packages in 10.571s found 0 vulnerabilities

$ nodemon project02

Error Message:

[nodemon] starting `node project02.js`
/home/Project02/node_modules/hoek/lib/index.js:553
    throw new Assert.AssertionError({
    ^

AssertionError [ERR_ASSERTION]: pattern should not use global or sticky mode
    at new AssertionError (internal/assert.js:269:11)
    at Object.exports.assert (/home/Project02/node_modules/hoek/lib/index.js:553:11)
    at internals.String.regex (/home/Project02/node_modules/joi/lib/types/string/index.js:122:14)
    at Object.<anonymous> (/home/Project02/helpers/routeHelpers.js:47:27)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
[nodemon] app crashed - waiting for file changes before starting...

What am I missing and what do I need to do to fix this?

1 Answers

This error is from @hapi/joi when you upgraded to v14. There is a breaking change with regular expressions for object.pattern and string.regex. You can no longer use global (g) or sticky (y) flags. These flags were previously ignored, but now they are rejected.

For example the global was ignored joi.string().regex(/^[a-z0-9_-]{1,25}$/ig)

Now the global flag must be removed joi.string().regex(/^[a-z0-9_-]{1,25}$/i)

Reference the @hapi/joi release notes https://github.com/hapijs/joi/issues/1615

Related