question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subscriptions Transport WS module not found during npm dev but fine in npm build

See original GitHub issue

Do NOT ignore this template or your issue will have a very high chance to be closed without comment.

Describe the bug

Error in chrome console. Uncaught SyntaxError: The requested module '/@modules/subscriptions-transport-ws/dist/client.js' does not provide an export named 'SubscriptionClient'

A clear and concise description of what the bug is.

During yarn dev, Vite is unable to find exports from subscriptions-transport-ws although once the project is built for production using yarn build it works fine.

Reproduction

yarn add subscriptions-transport-ws import { SubscriptionClient } from “subscriptions-transport-ws”; into any vue file run yarn dev load website and go to console.

<template>
  <img alt="Vue logo" src="./assets/logo.png" />
  <HelloWorld />
</template>

<script lang="ts">
import HelloWorld from "./components/HelloWorld.vue";
import { SubscriptionClient } from "subscriptions-transport-ws";
import { useClient, handleSubscriptions, defaultPlugins } from "villus";

const subscriptionClient = new SubscriptionClient(
  "ws://xxxxx/graphql",
  { reconnect: true },
);

const subscriptionForwarder = (operation: any) =>
  subscriptionClient.request(operation);

export default {
  name: "App",
  components: {
    HelloWorld,
  },
  setup() {
    useClient({
      url: "https://xxxxx/graphql",
      use: [handleSubscriptions(subscriptionForwarder), ...defaultPlugins()],
    });
  },
};
</script>

A reproduction is required unless you are absolutely sure that the the problem is obvious and the information you provided is enough for us to understand what the problem is. If a report has only vague description (e.g. just a generic error message) and has no reproduction, it will be closed immediately.

System Info

  • required vite version: rc4
  • required Operating System: osx
  • required Node version: 15
  • Optional:
    • npm/yarn version
    • Installed vue version (from yarn.lock or package-lock.json)
    • Installed @vue/compiler-sfc version

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lewebsimplecommented, Oct 26, 2020

This works just fine :

import ws from "subscriptions-transport-ws";
const subscriptionClient = new ws.SubscriptionClient( /* ... */ );
0reactions
underfincommented, Oct 29, 2020

The subscriptions-transport-ws is common js module.Vite only support es module by defalut, you can ask the maintainer export es module package.

Other, vite can support cjs with optimizer and you can use it as @lewebsimple said. For cjs named importer, you can track here https://github.com/vitejs/vite/issues/720.

Read more comments on GitHub >

github_iconTop Results From Across the Web

It gives an error while installing vue/cli. Someone help me
For help migrating Apollo software to `graphql-ws`, ... vue : File C:\Users\tolga\AppData\Roaming\npm\vue.ps1 cannot be loaded because ...
Read more >
graphql-ws - npm
Start using graphql-ws in your project by running `npm i graphql-ws`. ... TypeScript icon, indicating that this package has built-in type ...
Read more >
graphql-subscriptions-client - npm package | Snyk
A simpler client for graphql subscriptions based on apollographql/subscriptions-transport-ws For more information about how to use this package see README.
Read more >
installing packages (npm)...npm warn config global `--global ...
If it is not working, try updating npm using npm install npm@latest -g. enter image description here. Open side panel. When I install...
Read more >
GraphQL Code Libraries, Tools and Services
A JavaScript library for application development using cloud services, which supports GraphQL backend and React components for working with GraphQL data.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found