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

version 5.0 needs babel retranspilation #34

Closed
dpinol opened this issue Jun 1, 2021 · 3 comments
Closed

version 5.0 needs babel retranspilation #34

dpinol opened this issue Jun 1, 2021 · 3 comments

Comments

@dpinol
Copy link

dpinol commented Jun 1, 2021

Hi,
up to version 4.0 of escape-string-regexp, the function was exported with

module.exports = string => {
   if (typeof string !== 'string') {

In 5.0, it's exported with

 export default function escapeStringRegexp(string) 

This causes several issue:

With jest

2021-04-28T14:35:50.2003261Z   ● Test suite failed to run
2021-04-28T14:35:50.2003929Z 
2021-04-28T14:35:50.2004617Z     Jest encountered an unexpected token
2021-04-28T14:35:50.2005114Z 
2021-04-28T14:35:50.2006246Z     This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
2021-04-28T14:35:50.2006967Z 
2021-04-28T14:35:50.2007817Z     By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
2021-04-28T14:35:50.2008852Z 
2021-04-28T14:35:50.2009817Z     Here's what you can do:
2021-04-28T14:35:50.2011521Z      • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
2021-04-28T14:35:50.2014213Z      • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
2021-04-28T14:35:50.2015793Z      • If you need a custom transformation specify a "transform" option in your config.
2021-04-28T14:35:50.2017491Z      • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
2021-04-28T14:35:50.2018285Z 
2021-04-28T14:35:50.2019231Z     You'll find more details and examples of these config options in the docs:
2021-04-28T14:35:50.2020170Z     https://jestjs.io/docs/en/configuration.html
2021-04-28T14:35:50.2020730Z 
2021-04-28T14:35:50.2021241Z     Details:
2021-04-28T14:35:50.2021631Z 

/node_modules/escape-string-regexp/index.js:1
2021-04-28T14:35:50.2026390Z     ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export default function escapeStringRegexp(string) {

With ts-node:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: .../node_modules/escape-string-regexp/index.js
require() of ES modules is not supported.
require() of .../node_modules/escape-string-regexp/index.js from .../src/cms/callback.ts is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/dani/hubtype/botonic/packages/botonic-plugin-contentful/node_modules/escape-string-regexp/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)

With jest I managed to fix the error forcing the retranspilation in jest.config.js

transformIgnorePatterns: [
    'node_modules/(?!escape-string-regexp).+\\.(js|jsx)$',
  ]

with webpack I do something similar.

But with ts-node I'm not sure how to fix it.

Would you consider publishing the package with the previous export method to simplify the import process?

thanks

@sindresorhus
Copy link
Owner

Please read the release notes.

@sindresorhus
Copy link
Owner

Duplicate of #32

@noway
Copy link

noway commented Aug 24, 2021

I believe pure ESM module is not ready yet. As someone who uses ts-node, the support doesn't seem to be mature enough..

bootleq added a commit to bootleq/delocalizer that referenced this issue Dec 2, 2022
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

3 participants