question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Failed to load env from …\.env TypeError: Cannot read properties of undefined (reading 'split')" and "Module not found: Can't resolve '@builder.io/partytown/integration' in …" errors

See original GitHub issue

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System: Platform: win32 Arch: x64 Version: Windows 10 Enterprise Binaries: Node: 16.14.0 npm: N/A Yarn: N/A pnpm: N/A Relevant packages: next: 12.1.2-canary.0 react: 17.0.2 react-dom: 17.0.2

How are you deploying your application? (if relevant)

npx cross-env DEBUG=server:* node server.js

Describe the Bug

When I run npx cross-env DEBUG=server:* node server.js using next latest stable release 12.1.1 or latest canary release 12.1.2-canary.0, I get:

info  - Loaded env from C:\my-app\.env.local
error - Failed to load env from C:\my-app\.env TypeError: Cannot read properties of undefined (reading 'split')
    at C:\my-app\node_modules\@next\env\dist\index.js:1:311
    at Array.reduce (<anonymous>)
    at _interpolate (C:\my-app\node_modules\@next\env\dist\index.js:1:125)
    at expand (C:\my-app\node_modules\@next\env\dist\index.js:1:709)
    at processEnv (C:\my-app\node_modules\@next\env\dist\index.js:1:3638)
    at Module.loadEnvConfig (C:\my-app\node_modules\@next\env\dist\index.js:1:4443)
    at Object.loadConfig [as default] (C:\my-app\node_modules\next\dist\server\config.js:42:21)
    at NextServer.loadConfig (C:\my-app\node_modules\next\dist\server\next.js:114:48)
    at NextServer.getServer (C:\my-app\node_modules\next\dist\server\next.js:120:39)
    at NextServer.prepare (C:\my-app\node_modules\next\dist\server\next.js:96:35)
warn  - SWC minify release candidate enabled. https://nextjs.org/docs/messages/swc-minify-enabled
event - compiled client and server successfully in 14.4s (174 modules)
  server:main > Ready on http://localhost:3000 +0ms
GET / 307 - - 18.663 ms
wait  - compiling / (client and server)...
warn  - ./node_modules/next/dist/pages/_document.js
Module not found: Can't resolve '@builder.io/partytown/integration' in 'C:\my-app\node_modules\next\dist\pages'

However, on next previous stable release 12.1.0, it works normally without any of these warnings.

Expected Behavior

App to work normally without either of these warnings: error - Failed to load env from C:\my-app.env TypeError: Cannot read properties of undefined (reading ‘split’) warn - ./node_modules/next/dist/pages/_document.js Module not found: Can’t resolve ‘@builder.io/partytown/integration’ in ‘C:\my-app\node_modules\next\dist\pages’

To Reproduce

Use .env file, and custom _document.js on stable release 12.1.1 or canary release 12.1.2-canary.0.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
housseindjirdehcommented, Apr 1, 2022

Thanks for the details everyone. Looks like there are two separate issues here:

  • Failed to load env from …\.env TypeError: Cannot read properties of undefined (reading 'split'): Like some of you have already noticed, you need to escape the $ character (see note in docs)
  • Module not found: Can't resolve '@builder.io/partytown/integration': This may be due to a setup issue, but I’ve just included a patch for webpack to not parse the require of the package server-side which should remove any likelihood of it erroring due to not being resolved. This should prevent this error from popping up when it shouldn’t 😃
1reaction
sdeaghcommented, Apr 1, 2022

My steps to recreate:

  1. yarn create next-app testsite
  2. cd testsite
  3. yarn build (worked fine)
  4. create blank file .env.local
  5. yarn build (worked fine)
  6. add an environment variable, e.g., MY_TEST_ENV_VARIABLE=“hello”
  7. yarn build (worked fine)
  8. edit environment variable to include a $ symbol e.g., MY_TEST_ENV_VARIABLE=“hello$”
  9. yarn build now results in:

error - Failed to load env from /Users/******/Dev/testsite/.env.local TypeError: Cannot read properties of undefined (reading ‘split’)

**EDIT: READING THE DOCS - The $ symbol now needs to be escaped i.e. MY_TEST_VARIABLE="hello\$"**

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to load env - Cannot read properties of undefined ...
error - Failed to load env from C:\Users\user\Desktop\project\.env TypeError: Cannot read properties of undefined (reading 'split') ...
Read more >
Why I receive error: TypeError: Cannot read property of 'split ...
In your code, it is seems that ` process.env.DB_CREDENTIALS` is undefined. So, split() function does not exists on. I suggest you to read...
Read more >
Bud 6.0 - Cannot read properties of undefined (reading 'split')
After upgrading to bud 6.0 and following first path from the Bud v6.0.0 released whenever I am trying to use yarn build /...
Read more >
cannot read properties of undefined (reading 'module')
Your issue is that your .find() method is returning undefined , so you can't access properties on product such as .name as it...
Read more >
Env Variables and Modes - Vite
Env Variables and Modes #. Env Variables #. Vite exposes env variables on the special import.meta.env object. Some built-in variables are available in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found