I am building a snowpack app right now, and I would like to import socket.io client
in the frontend (For intellisense and offline dev testing). However, socket.io
only exports the backend materials when using import ... from 'socket.io'
.
Normally, I use
import { io } from 'socket.io/client-dist/socket.io.js';
Which gets all the correct files and exports, however, when building with snowpack I get this error:
Package exports for 'C:\dev\JS\Node+Browser\foo\node_modules\socket.io' do not define a './client-dist/socket.io.js' subpath
Which fails the build, stopping everything.
Right now, my snowpack.config
is really bare bones:
module.exports = {
buildOptions: {
out: 'dist/client'
},
mount: {
"src/client": "/"
}
}
All of the rest of my modules run fine, because they are all imported with only import ... from 'module-name
. I understand what the error is saying, but I cant find anything online or thing of anything to solve it. Does anyone know how to fix this?
NOTE: This is a "hacky" fix that I think is messy and can not be used for larger projects.
I patched this by editing the
package.json
of thesocket.io
package (Innode_modules
) to use a temporary export alias that was exactly the same as the real directory path:node_modules/socket.io/package.json