Cannot read property 'split' of undefined

16 views
Skip to first unread message

Maria Otero

unread,
Jun 16, 2020, 7:45:49 PM6/16/20
to NYT Library Community
Hi, I am trying to create a library for my company and when running npm run watch I get the following error, does anyone know what is going on? 

 /Users/Documents/library-master/server/userAuth.js:12

[0] const domains = new Set(process.env.APPROVED_DOMAINS.split(/,\s?/g))

[0]                                                      ^

[0] 

[0] TypeError: Cannot read property 'split' of undefined

[0]     at Object.<anonymous> (/Users/Documents/library-master/server/userAuth.js:12:54)

[0]     at Module._compile (internal/modules/cjs/loader.js:778:30)

[0]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

[0]     at Module.load (internal/modules/cjs/loader.js:653:32)

[0]     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

[0]     at Function.Module._load (internal/modules/cjs/loader.js:585:3)

[0]     at Module.require (internal/modules/cjs/loader.js:692:17)

[0]     at require (internal/modules/cjs/helpers.js:25:18)

[0]     at exports.requireWithFallback (/Users/kora/Documents/library-master/server/utils.js:52:12)

[0]     at Object.<anonymous> (/Users/kora/Documents/library-master/server/index.js:18:18)

[0] [nodemon] app crashed - waiting for file changes before starting...

Isaac White

unread,
Jun 16, 2020, 8:15:18 PM6/16/20
to Maria Otero, NYT Library Community
Hi Maria,

We should make that error message a little more straightforward. In the meantime, I'm happy to try and help.

The stack trace suggests that an environment variable (APPROVED_DOMAINS) is not being set for your local copy of Library. Currently, the portion of code that the trace links to crashes on that value being missing.

To resolve the issue, you can set that environment variable in your local .env file, like this:
APPROVED_DOMAINS=newsunroad.com

There are a number of other environment variables that need to be set as well, which are listed here

Hope that's helpful.

Isaac

--
You received this message because you are subscribed to the Google Groups "NYT Library Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nyt-library-comm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nyt-library-community/fb00ac10-c006-40b6-985f-03a918441976o%40googlegroups.com.

Maria Otero

unread,
Jun 23, 2020, 10:57:05 PM6/23/20
to Isaac White, NYT Library Community
Hi Isaac,

Thank you very much for all your help. I am new to programming so do forgive me if my question are too obvious. 

I went ahead and added a list of approve domains to the .env file, tried adding them with and without quotations but I still get the same error message.

I am imagining there might be another variable that is not set up correctly so I went ahead and created a Heroku account and created an "app" for my library. I was still not able to figure out how to add my project to it or set approved_domains. Is there a place that you can point to me that shows me how to do this?

Again, thanks for your help

Maria


--
María Otero
Operations Analyst, New Sun Road

  

Isaac White

unread,
Jun 28, 2020, 9:15:41 PM6/28/20
to Maria Otero, NYT Library Community
Hi Maria,

You're right that there are some other environment variables the app may need as well. However, this specific error message would probably only occur if the value for the APPROVED_DOMAINS environment variable is not being set properly.

It could be unrelated, but your stack trace looks a little strange. In particular, this part:

[0] TypeError: Cannot read property 'split' of undefined

[0]     at Object.<anonymous> (/Users/Documents/library-master/server/userAuth.js:12:54)

[0]     at Module._compile (internal/modules/cjs/loader.js:778:30)

[0]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

[0]     at Module.load (internal/modules/cjs/loader.js:653:32)

[0]     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

[0]     at Function.Module._load (internal/modules/cjs/loader.js:585:3)

[0]     at Module.require (internal/modules/cjs/loader.js:692:17)

[0]     at require (internal/modules/cjs/helpers.js:25:18)

[0]     at exports.requireWithFallback (/Users/kora/Documents/library-master/server/utils.js:52:12)

[0]     at Object.<anonymous> (/Users/kora/Documents/library-master/server/index.js:18:18)


Is it possible you have two copies of Library locally? Normally I would expect the start of the highlighted paths to be consistent, which could hint at the possibility of one directory having a copy of the .env but the other does not. The .env needs to be present in the same directory you are in when running npm run watch.

Isaac


Maria Otero

unread,
Jun 29, 2020, 3:59:01 PM6/29/20
to Isaac White, NYT Library Community
Thank you Isaac for all your help, I will look into it
Reply all
Reply to author
Forward
0 new messages