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

Module not found: Can't resolve 'ky' with version 0.28 #340

Closed
LoiKos opened this issue May 5, 2021 · 18 comments
Closed

Module not found: Can't resolve 'ky' with version 0.28 #340

LoiKos opened this issue May 5, 2021 · 18 comments
Labels
bug Something isn't working

Comments

@LoiKos
Copy link

LoiKos commented May 5, 2021

Upgrading to [email protected], i get Module not found: Can't resolve 'ky'.

When i open vs code and look at the 'ky' module it refers to index.d.ts and load typescript definition instead of index.js.

I use create-react-app i don't know if that help you but it works perfectly fine with [email protected]

@sholladay
Copy link
Collaborator

sholladay commented May 5, 2021

Hi @LoiKos and thanks for reporting this. I was able to reproduce the issue relatively easily with some educated guesses. That said, in the future, please provide reproduction steps or a sample repository. There are people out there like me who don't use CRA.

Here are the reproduction steps:

  1. npx create-react app foo
  2. cd foo && npm install ky
  3. Open src/index.js and add import ky from 'ky'
  4. npm start

I was able to fix the problem by modifying node_modules/ky/package.json to use main instead of exports, which is slightly confusing because Ky v0.27.0 also uses exports, albeit with a different value, and somehow that works. Perhaps the CRA tooling only has partial or buggy support for exports? The only difference between the exports value in v0.27.0 and v0.28.0 that stands out to me is that v0.28.0 uses a subdirectory.

Arguably, this is likely a problem with CRA itself. But at the same time, maybe we should consider going back to main for ecosystem compatibility.

@sholladay sholladay added the bug Something isn't working label May 5, 2021
@LoiKos
Copy link
Author

LoiKos commented May 5, 2021

Yeah sorry for missing information. I was able to reproduce in codeSandbox : https://codesandbox.io/s/vigilant-hooks-mw7xl?file=/src/App.tsx
If someone need to see the problem in action

@Eric-Dunaway
Copy link

having the same problem with a vue-cli app

Todo:
will add steps to reproduce

@sholladay
Copy link
Collaborator

@LoiKos and @Eric-Dunaway could you please also file an issue on the repos for those tools?

Once that's done, I'll create a branch of Ky that you can use as a workaround.

@719media
Copy link

719media commented May 6, 2021

This is a blocker for me to upgrade to the latest ky 0.28.0 (using vue-cli). I don't know the ins and outs of npm package deployment, but when I use over 80+ dependencies directly in my application with vue-cli, and this is the first time such a problem has ever happened to me with any library, seems like perhaps having other vendors "fix" this issue (even if they are in the wrong) may not be the best solution? Just a humble suggestion :)

Repro:
npm install -g @vue/cli
vue create -p default testerson
cd testerson
npm install ky
import ky from 'ky'
Open src/main.js and add import ky from 'ky'
npm run serve

Result:

This dependency was not found:

* ky in ./src/main.js

I appreciate the work you do on this library, it is awesome! Thank you for your work!

@sholladay
Copy link
Collaborator

With that logic, you might as well ask the Node.js folks to stop adding new features, and remove support for the exports field as a supported feature in Node, since apparently we can't start using those things without it being our fault when other tools break, and we shouldn't ask those tools to update, even if we've waited years for them to do so.

I don't intend that to sound so flippant, but that's the ultimate conclusion of what you're suggesting.

@719media
Copy link

719media commented May 6, 2021

It's all good, you understand the actual workings and I don't. I'm just commenting as a consumer of your product and letting you know my experience. Thanks, hope this gets fixed either way as I'd love to continue to use ky in it's most modern form!

@LoiKos
Copy link
Author

LoiKos commented May 7, 2021

I have created an issue inside CRA facebook/create-react-app#10933 feel free to add more information as i'm not really sure i understand where the problem comes from.

@Fnxxxxo
Copy link

Fnxxxxo commented May 10, 2021

It seems the latest package.json of ky lacks both main and module setting. Webpack cannot find the entry. After I add alias the error resolved.

{
  resolve: {
    alias: {
      ky: path.join(__dirname, '../../node_modules/ky/distribution/index.js')  // Depend on where your ky located.
    }
  }
}

@davidgg
Copy link

davidgg commented May 10, 2021

Same here, I'm downgrading to 0.27.0 for now.

axelhunn added a commit to folio-org/stripes-acq-components that referenced this issue May 13, 2021
* add ["@babel/plugin-proposal-private-methods", \{ "loose": true }] to Babel plugins (due to Babel's warning)
* adjust mocking Ky (see sindresorhus/ky#170 and sindresorhus/ky#340)
* add TS transformation
@Labham-Jain
Copy link

Same issue here...

@Labham-Jain
Copy link

I was using 0.28.1 but downgrading to 0.27.0 resolved the issue

@ukkz
Copy link

ukkz commented May 19, 2021

I've same issue with ky-universal.
I fixed like that below temporally at ~/node_modules/ky-universal/browser.js:

//import ky from 'ky';
import ky from '@/node_modules/ky/distribution';

export default ky;

@sholladay
Copy link
Collaborator

Apparently the unpkg CDN is also having trouble with our package.json. Today I discovered that importing Ky from https://unpkg.com/ky is broken. It results in a 404 because it doesn't find index.js.

@sindresorhus
Copy link
Owner

https://github.com/sindresorhus/ky/releases/tag/v0.28.2

@LoiKos
Copy link
Author

LoiKos commented May 25, 2021

Working fine for me ! If others can confirm it is working fine too, i could close the issue.

@ux-engineer
Copy link

Just upgraded to 0.28.2. from 0.27.x, which resolved the first error that was produced by upgrading to 0.28.1.

However, after this upgrade I'm unable to import types from this library, as TypeScript 4.2.4 is giving errors about not finding these type exports 'has no exported member'.

import type { BeforeRequestHook, BeforeRetryHook, NormalizedOptions, AfterResponseHook } from 'ky';

@lpellegr
Copy link

@LoiKos The fix is solving the issue I had with ESM imports.

@ux-engineer The following is working for me:

import type {BeforeRequestHook, BeforeRetryHook, AfterResponseHook} from 'ky/distribution/types/hooks';
import type {NormalizedOptions} from 'ky/distribution/types/options';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests