Vercel Toolbar + Turbo: TypeError: Cannot create property 'env' on string 'phase-development-server'
Answered
English Spot posted this in #help-forum
English SpotOP
Apologies if this doesn't belong here. Thought I'd ask if anyone's had success setting up the Vercel Toolbar in Turborepo?
I've read this and wasn't sure if this is the solution since the problem is different: https://nextjs-forum.com/post/1145009379054207006
1. I linked the project from the root of the Turborepo
2. Inside my
3. I imported the
4. When I run the dev server I get this:
apps/web/next.config.js
I've read this and wasn't sure if this is the solution since the problem is different: https://nextjs-forum.com/post/1145009379054207006
1. I linked the project from the root of the Turborepo
2. Inside my
apps/web project I see the .vercel file with the projectId and the orgId present.3. I imported the
withVercelToolbar to my next.config.js and exported the default config with it.4. When I run the dev server I get this:
> dotenv -e .env.local -- "next" "dev"
file:///Users/srs/GitHub/studio/node_modules/@vercel/toolbar/dist/plugins/next.js:4
`)})}).get("/branch",(r,e)=>{e.json({branch:i()})});function E(r){let e=r??x(),t=w((n,c)=>B.handler(n,c));return t.unref(),t.on("error",()=>{}),t.listen(e,()=>{o(`Toolbar dev server listening on port ${e}`),l()}),e}var p=43214;function x(){try{let r=L.sync("node",[h.join(_,"..","scripts","get-free-port.cjs")]);if(!r.stdout&&r.stderr)return o("Unexpected error when getting a free port",r.stderr),p;let e=Number(S(r.stdout).trim());return isNaN(e)?(o(`Error parsing free port: '${r.stdout}'`),p):e}catch(r){return o("Error running the get-free-port script",r),p}}function T(r={}){return e=>{if(process.env.NODE_ENV!=="development")return e;let t=v(),n=i();if(!t)return e;e.env||(e.env={}),o("Found local project info",{...t,gitBranch:n});let c=E(r.devServerPort);return Object.assign(e.env,{VERCEL_TOOLBAR_OWNER_ID:t.ownerId,VERCEL_TOOLBAR_PROJECT_ID:t.projectId,VERCEL_TOOLBAR_BRANCH:n??"",VERCEL_TOOLBAR_DEBUG:process.env.VERCEL_TOOLBAR_DEBUG??"",VERCEL_TOOLBAR_SERVER:`http://localhost:${c}`}),e}}var er=T;export{er as default,T as withVercelToolbar};
^
TypeError: Cannot create property 'env' on string 'phase-development-server'
at file:///Users/srs/GitHub/studio/node_modules/@vercel/toolbar/dist/plugins/next.js:4:686
at normalizeConfig (/Users/srs/GitHub/studio/node_modules/next/dist/server/config-shared.js:145:18)
at loadConfig (/Users/srs/GitHub/studio/node_modules/next/dist/server/config.js:712:68)
at async nextDev (/Users/srs/GitHub/studio/node_modules/next/dist/cli/next-dev.js:197:14)
at async main (/Users/srs/GitHub/studio/node_modules/next/dist/bin/next:155:5)
Node.js v20.11.1apps/web/next.config.js
import { fileURLToPath } from 'url';
import withVercelToolbar from '@vercel/toolbar/plugins/next';
import _jiti from 'jiti';
const jiti = _jiti(fileURLToPath(import.meta.url));
// Import env files to validate at build time. Use jiti so we can load .ts files in here.
jiti('./src/env');
jiti('@yocxo/auth/env');
/** @type {import("next").NextConfig} */
const config = {
images: {
formats: ['image/avif', 'image/webp'],
remotePatterns: [
{
protocol: 'https',
hostname: 'basehub.earth',
},
],
},
reactStrictMode: true,
transpilePackages: [
'@yocxo/api',
'@yocxo/auth',
'@yocxo/db',
'@yocxo/ui',
'@yocxo/validators',
],
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
};
export default withVercelToolbar(config);Answered by English Spot
I guess the answer was obvious except to me.
1. From root of repo ran
2. Then despite being contrary to what Vercel CLI docs suggest, I ran the
3. Created HOC to add the toolbar with ESM
1. From root of repo ran
vc link --cwd apps/path-name in my case apps/web2. Then despite being contrary to what Vercel CLI docs suggest, I ran the
vc link command again from my apps/web project3. Created HOC to add the toolbar with ESM
import { fileURLToPath } from 'url';
import createJiti from 'jiti';
const withVercelToolbar = (
await import('@vercel/toolbar/plugins/next')
).default();
createJiti(fileURLToPath(import.meta.url))('./src/env');
/** @type {import("next").NextConfig} */
const config = {
images: {
formats: ['image/avif', 'image/webp'],
remotePatterns: [
{
protocol: 'https',
hostname: 'basehub.earth',
},
],
},
reactStrictMode: true,
transpilePackages: [
'@yocxo/api',
'@yocxo/auth',
'@yocxo/db',
'@yocxo/ui',
'@yocxo/validators',
],
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
};
const withToolbarConfig = withVercelToolbar(config);
export default withToolbarConfig;1 Reply
English SpotOP
I guess the answer was obvious except to me.
1. From root of repo ran
2. Then despite being contrary to what Vercel CLI docs suggest, I ran the
3. Created HOC to add the toolbar with ESM
1. From root of repo ran
vc link --cwd apps/path-name in my case apps/web2. Then despite being contrary to what Vercel CLI docs suggest, I ran the
vc link command again from my apps/web project3. Created HOC to add the toolbar with ESM
import { fileURLToPath } from 'url';
import createJiti from 'jiti';
const withVercelToolbar = (
await import('@vercel/toolbar/plugins/next')
).default();
createJiti(fileURLToPath(import.meta.url))('./src/env');
/** @type {import("next").NextConfig} */
const config = {
images: {
formats: ['image/avif', 'image/webp'],
remotePatterns: [
{
protocol: 'https',
hostname: 'basehub.earth',
},
],
},
reactStrictMode: true,
transpilePackages: [
'@yocxo/api',
'@yocxo/auth',
'@yocxo/db',
'@yocxo/ui',
'@yocxo/validators',
],
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
};
const withToolbarConfig = withVercelToolbar(config);
export default withToolbarConfig;Answer