Comments (6)
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.
Thanks for the explanation.
from ow.
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"
toow
'spackage.json
, or - Adding
"moduleResolution": "nodenext"
to the host project'stsconfig.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 (see comment below)"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.
from ow.
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.
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 asow>=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 toCommonJS
. 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 anERR_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.
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)
- Bug: `isValid` wrong typing HOT 3
- Package does not seem to work on node v8 `SyntaxError: Unexpected token {` HOT 1
- string.nonBlank validator HOT 1
- Error running with metro bundler
- generate objects from predicate HOT 3
- use browser-side HOT 1
- Unclear error message when checking NaN against the number type HOT 7
- Composition HOT 3
- Is there a way for an object predicate to differentiate between key with value `undefined`, and key not present? HOT 2
- should `ow.string.equals` be narrowing the type to specific strings? HOT 1
- wrong message: Expected `e` to be of type .... - instead of Expected argument to be of type HOT 3
- Show all possible errors exhaustively (option?)
- const values HOT 1
- Q: how to make custom type narrowing validator (i.e. Predicate<x>)? HOT 3
- metadata
- Documentation is 404
- Build errors when using ow in React app compiled with vite
- correct pattern for optional 'required' properties?
- Cannot find module 'ow' or its corresponding type declarations HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ow.