Reputation: 165
I'm trying to add environment variable inside .env
file in my nuxt project.
My Nuxt.js version is 2.15.3
Here is a snippet from my nuxt.config.js
:
export default {
publicRuntimeConfig: {
baseURL: process.env.BASE_URL
},
ssr: false,
target: 'static',
}
Here is my .env
file:
BASE_URL=https://my-url.smth
But when I run npm run dev
then nuxt gives error:
ERROR in ./.env 1:14 Module parse failed: Unexpected token (1:14) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.
I was guided by this article https://nuxtjs.org/tutorials/moving-from-nuxtjs-dotenv-to-runtime-config/
Also it DOES NOT work with the old way through the @nuxtjs/dotenv
.
Upvotes: 2
Views: 3235
Reputation: 46602
Wrap the variable in your .env
file in double quotes (and not single quotes) like this BASE_URL="https://my-url.smth"
.
I've written an in-depth answer on using env files with nuxt with more information on the subject.
As mentioned in it, please do not use the @nuxtjs/dotenv
package.
If you still have an issue, we'll probably need more details or at least a repro to help you more efficiently.
Upvotes: 2