curriculum icon indicating copy to clipboard operation
curriculum copied to clipboard

Confusing instructions for "ES6: Understand the Differences Between import and require" path

Open CharmedSatyr opened this issue 7 years ago • 4 comments

Describe the bug A challenge "Note" indicates that "In most cases, the file path requires a ./ before it; otherwise, node will look in the node_modules directory first trying to load it as a dependency."

Furthermore, the challenge instructions state that "The file where this function lives is called "string_functions", and it is in the same directory as the current file."

Therefore, users should expect the/a correct answer involves "./string_functions".

However, including ./ before the file name causes the challenge to fail.

To Reproduce

  1. Go to 'https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/understand-the-differences-between-import-and-require'
  2. Enter import { capitalizeString } from "./string_functions"; below "use strict";
  3. The challenge fails with a Cannot read property 'capitalizeString' of undefined error.
  4. Replace the previous entry with import { capitalizeString } from "string_functions";
  5. The challenge passes.

Expected behavior The challenge should pass when the user includes ./ in front of the imported filename. Or, the challenge should specify that the "string_functions" file lives in the node_modules directory or that no ./ is needed in this challenge.

Screenshots screenshot from 2018-06-30 08-10-41

Desktop (please complete the following information):

  • OS: Debian buster/sid
  • Browser Brave
  • Version 0.23.19-1

Additional context Subsequent ES6 challenges share this problem, but I will hold on filing issues for them until this one is resolved.

CharmedSatyr avatar Jun 30 '18 13:06 CharmedSatyr

Another nit pick, "node" should be capitalized.

ethan-dorta avatar Jul 10 '18 18:07 ethan-dorta

I will claim and fix

nathanhannig avatar Aug 02 '18 19:08 nathanhannig

Can anyone confirm? I believe this is the fix

"getUserInput => assert(getUserInput('index').match(/import\\s+\\{\\s*capitalizeString\\s*\\}\\s+from\\s+(\"|')(\\.\\/)*string_functions\\1/g), 'valid <code>import</code> statement');"

nathanhannig avatar Aug 04 '18 06:08 nathanhannig

so the issue is that the tests (not a specific test) fail because the capitalize function is being pulled from the window object, so when you change how it is imported the code fails to run.

I think the description of these challenges need to be improved to state we aren't importing from a file for the challenge but from an unorthodox method of using the window object.

nathanhannig avatar Aug 06 '18 20:08 nathanhannig