Home > database >  How do I add a symlink from project's node_modules?
How do I add a symlink from project's node_modules?

Time:12-31

I've been following a tutorial on how to code a Password Manager using React, Node.js and MYSQL. I suddenly got this error telling me the file, /EncrpytionHandler, falls outside of the project src/ directory. Though, the file structure is the same as it is in the video. I'm not sure what to do, being that even when I do move the file, the error still occurs. Here is the video to the tutorial and a screeshot of my workspace:

Compiled with problems: ERROR in ./src/App.js 9:0-66 Module not found: Error: You attempted to import ../../server/EncryptionHandler which falls outside of the project src/ directory. Relative imports outside of src/ are not supported. You can either move it inside src/, or add a symlink to it from project's node_modules/.

Coding a Password Manager - ReactJS, NodeJS, MySQL

Image of my workspace

CodePudding user response:

You attempt to import file outside of the project src/ directory. This functionality was added to "create-react-app" not so long ago. You might want to resolve it by simply adding the same file to your frontend app, say, to src/util/ directory, or proceed with this answer:

ReactJS import component outside src/ directory

CodePudding user response:

Note that you have run the server on the src folder, so it is normal for it to run as the root directory of your server process, so this process has no right to exit its root, so it is best to add this module to the src folder To make exporters available in that folder, otherwise you can create a Symlink for it as follows:

create this file with name "createSym.js" in src dir and And put the following program in it :

// Node.js program to demonstrate the
// fs.symlink() method
  
// Import the filesystem module
const {symlink} = require('fs');
  
symlink("../../server/EncryptionHandler.js",
        "./EncryptionHandler.js", 'file', (err) => {
  if (err) console.log(err)
  else console.log("done");
);

and run this with node in src directory<as current work director(cwd or pwd)>

node createSym.js

Note that to do this, you need to have the required permission

  • Related