Socket io client error: SyntaxError: The requested module '#socket.io/component-emitter' is expected to be of type CommonJS - socket.io

I'm using nextjs, I install the package socket.io-client, and when trying to import, according to the docs:
import { io } from "socket.io-client";
I'm receiving this error:
SyntaxError: The requested module '#socket.io/component-emitter' is expected to be of type CommonJS, which does not support named exports. CommonJS modules
can be imported by importing the default export.
For example:
import pkg from '#socket.io/component-emitter';
const { Emitter } = pkg;
The import is in index.js

I found out that the reason is an outdated Node version I was using!

Related

How to import and use protobuf timestamppb package in a proto file?

I want to use timestamppb package in my protobufs because it helps to easily convert Timestamp to Go time. Time. However, I can't figure out how to import it into the .proto file. When I try I get the following error Import "google.golang.org/protobuf/types/known/timestamppb" was not found or had errors.
I looked at the documentation timestamppb docs for the timestamppb package but it seems there are no examples of how to use it in .proto files.
syntax = "proto3";
import "google.golang.org/protobuf/types/known/timestamppb";
// import "google.golang.org/protobuf/types/known/timestamppb.proto"; I tried this too but no luck
message Example {
timestamppb.Timestamp example_time = 1;
}
The import for .proto files is:
import "google/protobuf/timestamp.proto";
The one that you tried is the path that is needed in Go Code in combination with go get.

How to Access Settings file from .py file - DRF

This is my project structure. I am trying to access settings.py file from lookups.py
I am importing using following code,
import os
import sys
import django
sys.path.append('/path/to/django/project')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'manageemployee.settings')
django.setup()
from manageemployee.apps.employee.hrmmongodb import DBMixin
from manageemployee.settings import EVENT_STORE_DICT
But I am getting the following error,
ModuleNotFoundError: No module named 'manageemployee'
It's better to use settings by importing the object django.conf.settings wherever it was needed instead of the settings file itself as you are trying,
Example:
from django.conf import settings
if settings.DEBUG:
# Do Something
So in your use case:
from django.conf import settings
EVENT_STORE_DICT = settings.EVENT_STORE_DICT
# Do Something
Note that django.conf.settings isn’t a module – it’s an object. So
importing individual settings is not possible:
from django.conf.settings import DEBUG # This won't work.
You can also find the detailed information in the Docs

Trying to import and use HTML from Drei but keep getting error

import { Html } from '#react-three/drei';
./node_modules/three-stdlib/lights/RectAreaLightUniformsLib.js
Attempted import error: 'DataUtils' is not exported from 'three'.
Ive tried looking at the documentation on drei for HTML
What I got still doesn't work
The native route of the library does not export Html or Loader. The default export of the library is web which does export Html and Loader.
import { Icosahedron, Html, OrthographicCamera } from '../../src'
import { HtmlProps, CalculatePosition } from 'web/Html'
When I use
import { Html, useProgress, useGLTFLoader } from "drei";
It works
but when I use
import { Html } from '#react-three/drei';
It breaks
I had a similar issue and solved it with npm install three-stdlib. I found the hint at the top of the README for the drei git repo: https://github.com/pmndrs/drei
A growing collection of useful helpers and abstractions for react-three-fiber.
npm install #react-three/drei
this package is using the stand-alone three-stdlib instead of three/examples/jsm

Rollup and Apollo websocket with subscriptions-transport-ws

I'm trying to use:
Svelte (https://github.com/sveltejs/template) and
Svelte-Apollo (https://github.com/timhall/svelte-apollo).
Using Rollup (https://github.com/sveltejs/template/blob/master/rollup.config.js) for the final bundle when compiling (npm run build) I got this error:
Error: "Subcription is not exported by node_modules/subscriptions-transport-ws/dist/index.js"
So I thought of solving with (https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports):
commonjs({
namedExports: {
'./node_modules/subscriptions-transport-ws/dist/index.js': ['SubscriptionClient']
}
}),
Now Rollup says:
index.js → public/bundle.js...
(!) Mixing named and default exports
Consumers of your bundle will have to use bundle['default'] to access the default export, which may not be what you want. Use `output.exports: 'named'` to disable this warning
(!) Missing shims for Node.js built-ins
Creating a browser bundle that depends on 'events', 'https', 'http', 'url', 'zlib' and 'stream'. You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins
(!) Unresolved dependencies
https://rollupjs.org/guide/en#warning-treating-module-as-external-dependency
events (imported by node_modules\ws\lib\websocket.js, node_modules\ws\lib\websocket-server.js, commonjs-external-events)
crypto (imported by node_modules\ws\lib\websocket.js, node_modules\ws\lib\websocket-server.js, node_modules\ws\lib\sender.js, commonjs-external-crypto)
https (imported by node_modules\ws\lib\websocket.js, commonjs-external-https)
net (imported by node_modules\ws\lib\websocket.js, commonjs-external-net)
http (imported by node_modules\ws\lib\websocket.js, node_modules\ws\lib\websocket-server.js, commonjs-external-http)
tls (imported by node_modules\ws\lib\websocket.js, commonjs-external-tls)
url (imported by node_modules\ws\lib\websocket.js, node_modules\ws\lib\websocket-server.js, commonjs-external-url)
stream (imported by node_modules\ws\lib\receiver.js, commonjs-external-stream)
zlib (imported by node_modules\ws\lib\permessage-deflate.js, commonjs-external-zlib)
bufferutil (imported by node_modules\ws\lib\buffer-util.js, commonjs-external-bufferutil)
utf-8-validate (imported by node_modules\ws\lib\validation.js, commonjs-external-utf-8-validate)
(!) Missing global variable names
Use output.globals to specify browser global variable names corresponding to external modules
events (guessing 'events')
crypto (guessing 'crypto')
https (guessing 'https')
http (guessing 'http')
net (guessing 'net')
tls (guessing 'tls')
url (guessing 'url')
zlib (guessing 'zlib')
bufferutil (guessing 'bufferutil')
stream (guessing 'stream')
utf-8-validate (guessing 'utf8Validate')
created public/bundle.js in 13.8s
What a mess. I'm just using web oriented libraries, why it complains about nodejs dependencies?!
So I added these lines in rollup.config.js:
import builtins from 'rollup-plugin-node-builtins'
import globals from 'rollup-plugin-node-globals'
...
plugins: [
globals(),
builtins(),
and all the previous errors are gone.
But now in browser I get:
Uncaught ReferenceError: exports is not defined
at client.js:45
It complains about this line (I think):
Object.defineProperty(exports, "__esModule", { value: true });
I'm totally lost.
I created a simple repo: https://codesandbox.io/s/zn1mnon8jl.
If you open it in codesandbox it works! Miracle! But if you download as a .zip and execute npm i && npm run dev you can see the problem.
What to do now?
Try adding this inline rollup plugin before the nodeResolve plugin
{
// needed to specifically use the browser bundle for subscriptions-transport-ws
name: 'use-browser-for-subscriptions-transport-ws',
resolveId(id) {
if (id === 'subscriptions-transport-ws')
return path.resolve('node_modules/subscriptions-transport-ws/dist/client.js');
},
},

Import web.go error after using goinstall

With halfdans advice, I was successfully able to use goinstall github.com/hoisie/web.go without any errors after installing git first. However, now when I try to compile the sample code given, go is not finding the web package. I get the error,
main.go:4: can't find import: web
On this code
package main
import (
"web"
)
func hello(val string) string { return "hello " + val }
func main() {
web.Get("/(.*)", hello)
web.Run("0.0.0.0:9999")
}
Is there something special I need to do in order for it to recognize the package? I found the package source at $GOROOT/src/pkg/github.com/hoisie/web.go/web. I tried github.com/hoisie/web.go/web as the import and it still did not like that.
If you install web.go through goinstall, you need to do:
import "github.com/hoisie/web.go"
Goinstall is still an experimental system. It would be nice if you didn't have to include the full path.
import web "github.com/hoisie/web.go"

Resources