"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 issueVerify 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:
- Created a year ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top GitHub Comments
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 therequire
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 😃My steps to recreate:
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\$"**