Why is the result of import module from node_modules different from that of direct import dist source file?.

problem description

it is normal to import modules from node_modules, but the direct import dist file is undefined,

related codes

// from node_modules, work well
import Layout from "@xxx/layout-auth/dist/layout" 

// from source dist, resolve to undefined
import Layout from "/User/xx...xxx/layout-auth/dist/layout" 

you have to see what the package.json,main field is


according to node's module parsing rules, if the second path is not in the current node path, it cannot be parsed


import import must be exported in the original file, but the dist folder is generally compiled files, may not be exported


this question found the answer?


because of the module under the node_module folder that you refer to, usually the project will be compiled into an es6 module by bebel, and then provided to the front end for reference. If you do not import du dialect from the node_module file (your current module may be the commonjs module), you need to simply configure the babel configuration file to translate the file you imported

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1beceb8-31b44.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1beceb8-31b44.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?