Coder Social home page Coder Social logo

Comments (6)

sindresorhus avatar sindresorhus commented on June 9, 2024

This is either a problem of having an outdated TypeScript version or Next.js not being able to handle this exports field in package.json. Neither of which are problems with this package.

from ow.

angelod1as avatar angelod1as commented on June 9, 2024

Thanks for the explanation.

from ow.

darkobits avatar darkobits commented on June 9, 2024

FWIW I'm able to reproduce this issue when upgrading to ow >=1.0.0 on Node 18.8.0 and TypeScript 4.9.4 in a vanilla project (no Nest et. al).

This can be fixed by either:

  • Adding a top-level "types": "./dist/index.d.ts" to ow's package.json, or
  • Adding "moduleResolution": "nodenext" to the host project's tsconfig.json.

To be fair, Typescript's documentation does indicate that it supports "exports.types", but without setting moduleResolution to nodenext, this behavior does not seem to work.

It might be a reasonable compromise to add a top-level "types" property to ow's package.json to ensure compatibility with consumers who either don't know to set moduleResolution to nodenext or are unable to due to some other requirement of their project. (see comment below)

from ow.

angelod1as avatar angelod1as commented on June 9, 2024

Coming back here because this is still happening in another project. Package.json:

    "@next/font": "13.1.5",
    "@types/node": "18.11.18",
    "@types/react": "18.0.27",
    "@types/react-dom": "18.0.10",
    "eslint": "8.32.0",
    "eslint-config-next": "13.1.5",
    "next": "13.1.5",
    "ow": "^1.1.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "typescript": "^4.9.5"

If I don't make what @darkobits wrote there, I get a Cannot find module 'ow' or its corresponding type declarations. error.

If I make it by adding moduleResolution, it errors with:

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("ow")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/Users/angelo/Documents/GIT/skoob-to-goodreads/package.json'

If you want to reproduce, this repo has this error.

from ow.

darkobits avatar darkobits commented on June 9, 2024

After doing some more digging and experimentation:

I think Sindre has already addressed this issue here in his Pure ESM Package gist, but to re-iterate what my take-aways are from that and other sources:

  • If projects are built using the TypeScript compiler and require moduleResolution: node for any reason, TypeScript will not work with packages that use export maps (such as ow>=1.0.0).
  • If projects are built using the TypeScript compiler and output CommonJS, there seems to be no way we can import ESM because unlike Babel, TypeScript will not preserve dynamic imports when module is set to CommonJS. Furthermore, this is an issue that may not be caught at compile time and only discovered when a consumer of your package tries to use it and encounters an ERR_REQUIRE_ESM fault.

As such, I think this issue is not a problem with ow but rather a very roundabout way of TypeScript telling us it is literally not compatible with ow>=1.0.0 based on our tsconfig.json setup, and the best solution for such users is to pin to an earlier version of ow.

from ow.

chr4ss12 avatar chr4ss12 commented on June 9, 2024

am not entirely sure what's going on or how this package is built, but it stops us upgrading to more recent versions of ow, perhaps the better approach will be to follow the commonly used patterns what most packages do (am not sure what that is sorry, but they just work without any hassle).

This stops us using the newer version on multiple projects.

from ow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.