-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
can't import sockjs-client to my vue project #7301
Comments
I found that this is happening because The following is some outputs extracted from
The browser field is like below, so "browser": {
"./lib/transport/driver/websocket.js": "./lib/transport/browser/websocket.js",
"eventsource": "./lib/transport/browser/eventsource.js",
"./lib/transport/driver/xhr.js": "./lib/transport/browser/abstract-xhr.js",
"crypto": "./lib/utils/browser-crypto.js",
"events": "./lib/event/emitter.js"
}, But it looks like when a "browser": "./inherits_browser.js", https://github.com/isaacs/inherits/blob/e6265134c91f9fb6a3d5e771f034ec94d20c6708/package.json#L16 |
I found a workaround here So you can use these aliases in vite.config.js to make sockjs-client work in your vite project export default defineConfig({
resolve: {
alias: [
{
find: 'eventsource',
replacement: './node_modules/sockjs-client/lib/transport/browser/eventsource.js',
},
{
find: 'events',
replacement: './node_modules/sockjs-client/lib/event/emitter.js',
},
{
find: 'crypto',
replacement: './node_modules/sockjs-client/lib/utils/browser-crypto.js',
},
],
},
}) |
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
eventsource:
"./node_modules/sockjs-client/lib/transport/browser/eventsource.js",
events: "./node_modules/sockjs-client/lib/event/emitter.js",
crypto: "./node_modules/sockjs-client/lib/utils/browser-crypto.js",
},
},
define: {
global: {},
},
}); This does remove all error messages,but now... [vite] connecting...
Opening Web Socket...
[vite] connected.
Whoops! Lost connection to http://localhost:3333/stomp With vue-cli, there are no errors and no extra processing required Maybe, I have to give up using vite. |
@158008001 mine config is working actually, I tested it. Try to change your config as I did. Not key-value pairs. But yes, I gave up. I have an experimental branch to check vite periodically. Every time I tested it, it created another issue :) Currently, the old way is better for me. |
Describe the bug
I am having an issue like this one: #1547
Except my imported library is sockjs-client
When I remove sockjs-client import line from my code (vuex store module), everything works great.
To reproduce it, I just created a vue project with vite
yarn create vite my-vue-app --template vue
Then import sockjs-client to somewhere in your project (like main.js)
I also added to index.html this polyfill:
I am not sure if it's directly related with vite. We tried to use socket.io but amazon created some issues with our backend/server structure. I don't know these topics. Therefore we are using this sockjs-client.
Reproduction
https://github.com/sametsafak/reproduction-of-sockjs-issue
System Info
Used Package Manager
yarn
Logs
Validations
The text was updated successfully, but these errors were encountered: