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

Dependency not found after npm install --save windows-1252 #7

Open
MartinKleikamp opened this issue Jul 31, 2021 · 8 comments
Open

Comments

@MartinKleikamp
Copy link

Had to substitute "exports" with "main" in package.json

@mathiasbynens
Copy link
Owner

Did you follow the README? https://github.com/mathiasbynens/windows-1252#installation

The library is now shipped as a JavaScript module, so you have to import instead of require.

@mathiasbynens
Copy link
Owner

Hmm, perhaps you were hitting this? e732af9 Please try with v3.0.1 and see if it works for you now.

@MartinKleikamp
Copy link
Author

Hmm, perhaps you were hitting this? e732af9 Please try with v3.0.1 and see if it works for you now.

thank you, but no effect. npm 7.20.3 and node v16.6.0 on win 10 64. npm 7.10.0 and node v14.15.1 on macOS 11.2.1 too.

@mathiasbynens
Copy link
Owner

Could you share more information? How can I reproduce this?

@MartinKleikamp
Copy link
Author

MartinKleikamp commented Aug 3, 2021

Could you share more information? How can I reproduce this?

I am using a Vue 3 - Vue.js https://v3.vuejs.org project, difficult to share, but does npm install --save windows-1252 and "import * as windows1252 from 'windows-1252'" work for you with my maximum versions of npm and node above? As I said, "main" does the job instead of the new npm-Syntax "exports", please see documentation of npm.

@kildareflare
Copy link

I'm seeing the same issue, using v3.0.1 in my node project.

npm: 6.13.4
node: 10.18.0
macOs: 10.15.6

npm i windows-1252

And then
import { encode } from 'windows-1252'

@mathiasbynens
Copy link
Owner

Could you share more information? How can I reproduce this?

I am using a Vue 3 - Vue.js https://v3.vuejs.org project, difficult to share, but does npm install --save windows-1252 and "import * as windows1252 from 'windows-1252'" work for you with my maximum versions of npm and node above? As I said, "main" does the job instead of the new npm-Syntax "exports", please see documentation of npm.

main is for packages that export CommonJS rather than actual JS modules (aka "ESM").

Could you share a gist with a package.json + a JS file that reproduces the issue? I cannot repro even with @kildareflare's steps. Are you perhaps using a transpiler that turns the import into a require?

@nicolasr75
Copy link

nicolasr75 commented Feb 15, 2022

Hello Mathias, I have a similar problem with using your package in a web app build with rollup. Unfortunately I currently don't have a demo project to reproduce it either but some more information: having only 'exports' in your package.json leads to the rollup error:

(!) Unresolved dependencies
https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
windows-1252 (imported by src\...\myfile.js)

rollup (actually @rollup/plugin-node-resolve) does not resolve the path and my app fails to load it.

When I add either the 'main' field or the 'module' field to your package.json, it works. So it looks like rollup considers 'main' and 'module' but not 'exports' alone. I have not checked the specification yet but here is an issue that discusses main/module and gives me the impression that adding 'module' would be the correct way for ESM: nodejs/node#34027

I checked a few packages I use regularly as examples but with mixed results:

Google LitElement uses this

"type": "module",
"main": "lit-element.js",
"module": "lit-element.js",

D3 on the other hand has this:

"main": "dist/d3.node.js",
"unpkg": "dist/d3.min.js",
"jsdelivr": "dist/d3.min.js",
"module": "index.js"

web-animations has this:

"main": "web-animations.min.js",

But they all build with rollup successfully.

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

4 participants