Typescript error with Sveltekit environment variables: RollupError: "PUBLIC_XXX" is not exported by "$env/dynamic/public" - sveltekit

I have this line of code in src/routes/+page.svelte
import {PUBLIC_SUPABASE_KEY} from '$env/dynamic/public';
When this builds on CI, I get this error:
#cozemble/frontend-main-app:build: RollupError: "PUBLIC_SUPABASE_KEY" is not exported by "$env/dynamic/public", imported by "src/routes/+page.svelte".
#cozemble/frontend-main-app:build: at error (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:1967:30)
#cozemble/frontend-main-app:build: at Module.error (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:12962:16)
#cozemble/frontend-main-app:build: at Module.traceVariable (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:13345:29)
#cozemble/frontend-main-app:build: at ModuleScope.findVariable (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:11826:39)
#cozemble/frontend-main-app:build: at FunctionScope.findVariable (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:6687:38)
#cozemble/frontend-main-app:build: at ChildScope.findVariable (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:6687:38)
#cozemble/frontend-main-app:build: at Identifier.bind (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:7782:40)
#cozemble/frontend-main-app:build: at CallExpression.bind (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:5575:28)
#cozemble/frontend-main-app:build: at CallExpression.bind (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:9299:15)
#cozemble/frontend-main-app:build: at VariableDeclarator.bind (file:///Users/mikehogan/repos/personal/cozemble/monorepo/node_modules/.pnpm/rollup#3.9.1/node_modules/rollup/dist/es/shared/rollup.js:5579:23)
#cozemble/frontend-main-app:build:  ELIFECYCLE  Command failed with exit code 1.
#cozemble/frontend-main-app:build: ERROR: command finished with error: command (/Users/mikehogan/repos/personal/cozemble/monorepo/frontend/main-app) pnpm run build exited (1)
This SO question suggests that the right Typescripts get generated from a .env file when you run npm run check. But it is my understanding that .env files are NOT to be checked into CI.
So this really easy approach to env vars in SvelteKit is defeating me. What is the right approach?

You just have to set the variable to anything so it is picked up by SvelteKit.
This can be done any number of ways, e.g. by running a command before the build to set it. What that command should look like depends on the build platform. Or if you are using a build pipeline with a GUI you probably could set the variable there.

Related

Failed to load plugin 'import' declared in 'package.json » eslint-config-react-app': Cannot find module 'typescript/package.json'

ERROR in [eslint] Failed to load plugin 'import' declared in 'package.json » eslint-config-react-app': Cannot find module 'typescript/package.json'
Require stack:
- C:\Users\USER\Desktop\bitcamp-homework_1\homework1\node_modules\eslint-plugin-import\lib\rules\no-duplicates.js
- C:\Users\USER\Desktop\bitcamp-homework_1\homework1\node_modules\eslint-plugin-import\lib\index.js
- C:\Users\USER\Desktop\bitcamp-homework_1\homework1\node_modules\#eslint\eslintrc\dist\eslintrc.cjs
I tried to create new react app with "npx create-react-app", after running npm start, this error appeared. I dont even using ts. what can I do?
I try reinstall but wont work.
Sometimes it runs without error.
[UPDATE] as i found out that was directory problem. (file in file)
add :
{
"eslint.workingDirectories": ["./front", "./back", "./shared"]
}
to settings.json

Import errors with the package #react-three/drei

I get the same error no matter what I import from the drei package, I am sure I have installed all the necessary packages and the latest versions, but I have this odd error.
Compiled with problems:X
ERROR in ./node_modules/#react-three/drei/core/Trail.js 104:38-54
export 'MeshLineGeometry' (imported as 'MeshLineGeometry') was not found in 'meshline' (module has no exports)
ERROR in ./node_modules/#react-three/drei/core/Trail.js 107:18-34
export 'MeshLineMaterial' (imported as 'MeshLineMaterial') was not found in 'meshline' (module has no exports)
ERROR in ./node_modules/meshline/dist/index.js 1:0-35
Module not found: Error: Can't resolve './MeshLineGeometry' in 'C:\Users\anura\Desktop\mysite\node_modules\meshline\dist'
Did you mean 'MeshLineGeometry.js'?
BREAKING CHANGE: The request './MeshLineGeometry' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
Downgrading not working solved it temporarily as follows.
Copied the index.js from node_modules/meshline/dist to lib/meshline in the root folder
Fixed by adding .js extensions to each line
Updated build steps as in the screenshots
Fixed index.js in lib/meshline
Build steps

sveltekit or esbuild error: Two output files share the same path but have different contents

Just now, for no reason I can figure out, when I run npm run dev on my sveltekit project, I get this error:
✘ [ERROR] Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js.map
✘ [ERROR] Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js
> Build failed with 2 errors:
error: Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js.map
error: Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js
error: Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js.map
error: Two output files share the same path but have different contents: node_modules/.vite/lodash_clonedeep.js
at failureErrorWithLog (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/esbuild#0.14.25/node_modules/esbuild/lib/main.js:1605:15)
at /repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/esbuild#0.14.25/node_modules/esbuild/lib/main.js:1251:28
at runOnEndCallbacks (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/esbuild#0.14.25/node_modules/esbuild/lib/main.js:1036:63)
at buildResponseToResult (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/esbuild#0.14.25/node_modules/esbuild/lib/main.js:1249:7)
at /repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/esbuild#0.14.25/node_modules/esbuild/lib/main.js:1358:14
at /repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/esbuild#0.14.25/node_modules/esbuild/lib/main.js:668:9
at handleIncomingPacket (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/esbuild#0.14.25/node_modules/esbuild/lib/main.js:765:9)
at Socket.readFromStdout (/repos/personal/docsndata-monorepo/common/temp/node_modules/.pnpm/esbuild#0.14.25/node_modules/esbuild/lib/main.js:635:7)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
I have done this hundreds of times and it worked.
In case it matters, my repo is a rushjs monorepo, and I continually do update my dependencies using it, so maybe some version has bumped some place in my dependency tree, but I don't know how to debug it.
What causes this error?
Ok, the issue is that one of the modules in my app imported lodash cloneDeep like this
import cloneDeep from lodash/cloneDeep
i.e from the full lodash npm module.
Another of my modules imported it using the more targeted npm module using
import cloneDeep from "lodash.clonedeep"
A very confusing error message, but I suppose it makes some sense.
The fix was to import cloneDeep consistently, I chose the latter approach.

failed to compile React projects

I am busy with a project of React and
When I want run a browser I get this error.
./src/Components/ui/icons.js
Module not found: Can't resolve './src/Resources/images/logos/manchester_city_logo' in 'C:\Users\Daniel\Desktop\mancity\src\Components\ui'
This error occurred during the build time and cannot be dismissed.
I made sure of correct names of folders. Is it a npm webpack?
You are most probably referring to a non-existed media file or using wrong file extension when importing manchester_city_logo (probably in icons.js)
Doublecheck the source path for desired media file in icons.js

"Can't load package" and "Use of internal package not allowed" when running goapp test

When I run the command:
goapp test ./...
I get the errors:
can't load package: package github.com/projectname/oauth2: code in directory /Users/nyname/go/src/github.com/projectname/oauth2 expects import "github.com/projectname/oauth2"
can't load package: package github.com/projectname/oauth2/clientcredentials: code in directory /Users/nyname/go/src/github.com/projectname/oauth2/clientcredentials expects import "github.com/projectname/oauth2/clientcredentials"
can't load package: package github.com/projectname/oauth2/google: code in directory /Users/nyname/go/src/github.com/projectname/oauth2/google expects import "github.com/projectname/oauth2/google"
can't load package: package github.com/projectname/oauth2/jws: code in directory /Users/nyname/go/src/github.com/projectname/oauth2/jws expects import "github.com/projectname/oauth2/jws"
package github.com/projectname/oauth2/jwt
imports github.com/projectname/oauth2/internal: use of internal package not allowed
It seems like no one else on my team get's this error.

Resources