-1

I have a file "test.js" in my "/constants" folder with the following content:

const test = "test!"

export default test

My page in the "/pages" folder should read the string from "test.js" and print it

import { test } from "../constants/test"

export default function Home() {
    console.log("imported string: " + test)
}

If I run it the browser I get the following output:

"imported string: undefined"

Why is it not reading the string from the file? The path is correct. VSCode autocomplete even finds the file while typing.

jan
  • 3,923
  • 9
  • 38
  • 78

2 Answers2

3

You are exporting the constant test as the default export, therefor your import statement should be changed from

import { test } from "../constants/test"

to

import test from "../constants/test"

NOTE: the {} imports are for NON-default exports

ThomasSquall
  • 644
  • 6
  • 21
1

If you want to use import { test } then you should use export test instead of using default
Because right now you're telling javascript to find specific export, not default.

owenizedd
  • 1,187
  • 8
  • 17