Home  >  Q&A  >  body text

Vue Error - Unable to resolve 'https' when importing package

I'm trying to create a Vue project and use the npm package to connect to the Retroachievements.org api to get some data, but I'm getting an error. This is my process from start to finish for creating a project and implementing a package.

I am using Windows 10, Node 16.17.0, npm 8.15.0, vue 2.6.14, vue CLI 5.0.8, raapijs 0.1.2.

The first solution below says he can run it without errors, but it looks exactly like the code I'm trying. Can anyone see the difference and cause of this error?

Edit: I've rewritten this post to make my process clearer and provide more information, such as versions.

P粉891237912P粉891237912282 days ago346

reply all(2)I'll reply

  • P粉107772015

    P粉1077720152024-01-11 16:01:24

    This solution works for me. I installed raapijs using npm install --save raapijs command. Then in my Vue version 2 component I used your code like this:

    const RaApi = require('raapijs');
    
    export default {
      
      data: () => ({
        api: null,
        user: '<USER_NAME>',
        apiKey: '<API_KEY>',
      }),
      
       created() {
        this.api = new RaApi(this.user, this.apiKey);
      },
    };

    reply
    0
  • P粉792673958

    P粉7926739582024-01-11 12:27:29

    It appears that the raapijs package is designed to be used in a Node environment, not in a Vue browser-based environment, so that's why I'm getting the error. The package itself is looking for the https package built into Node, but since it's not running in Node it doesn't find it.

    So I solved my problem by looking at the package's github repository and extracting the actual php API endpoints being used and using those directly in my application instead of using a package wrapper. Not as neat and tidy as I would have liked, but still a nice solution.

    reply
    0
  • Cancelreply