require.context(../to/file) that isn't a packages results in error
Closed this issue · 5 comments
in our packages directory we have a folder that just contains example files and isn't thus a real package
When using depviz 0.1.0 we get following error:
TypeError: Cannot read property 'name' of undefined
at /Users/wouterdebie/Projects/depviz/depviz.js:89:26
at async Promise.all (index 0)
at async addModuleRequireContext (/Users/wouterdebie/Projects/depviz/depviz.js:84:24)
at async Promise.all (index 0)
at async addModuleRequireContexts (/Users/wouterdebie/Projects/depviz/depviz.js:147:3)
at async Promise.all (index 1)
at async addPkgRequireContexts (/Users/wouterdebie/Projects/depviz/depviz.js:160:3)
at async Promise.all (index 43)
at async addRequireContexts (/Users/wouterdebie/Projects/depviz/depviz.js:181:3)
at async buildDeps (/Users/wouterdebie/Projects/depviz/depviz.js:233:5)
Using version 0.5.0 it passes.
Line of code that causes the error
const dependencies = await Promise.all(
dependencyModules.map(async mod => {
const cwd = path.join(pkgsPath, path.dirname(mod))
const {
package: { name: dependency }
} = await schedule(() => readPkgUp({ cwd }))
return dependency
})
)In version 0.1.0 packages read-pkg-up has been upgraded from version 6.0.0 to version 7.0.1 and it is thus not backwards compatible which results in the error above
I would recommend adding a package.json or moving the non-package out of the packages folder. 🙂
I was a bit wrong
unwrapper-schemas has a package.json file but depviz detects the subfolder unwrapper-schemas/schemas/json... and want to read its package.json file
$ /Users/wouterdebie/Projects/unwrapper-server/node_modules/.bin/depviz --require-context scripts/.. /tmp/unwrapper-server-1611058726.svg
[13:18:47] [INFO] Building dependency graph for /Users/wouterdebie/Projects/unwrapper-server
[13:18:47] [WARN] Since Acorn 8.0.0, options.ecmaVersion is required.
Defaulting to 2020, but this will stop working in the future.
[13:18:51] [LOG] >>>depModules
[13:18:51] [LOG] >>>depModules unwrapper-schemas/schemas/json/vast-2.0.json,unwrapper-schemas/schemas/json/vast-3.0.json,unwrapper-schemas/schemas/json/vast-4.0.json,unwrapper-schemas/schemas/json/vast-4.1.json,unwrapper-schemas/schemas/json/vast-4.2.json,unwrapper-schemas/schemas/json/vmap-1.0.json
[13:18:51] [LOG] >>>> /Users/wouterdebie/Projects/unwrapper-server/packages/unwrapper-schemas/schemas/json
[13:18:51] [LOG] >>>> /Users/wouterdebie/Projects/unwrapper-server/packages/unwrapper-schemas/schemas/json
[13:18:51] [LOG] >>>> /Users/wouterdebie/Projects/unwrapper-server/packages/unwrapper-schemas/schemas/json
[13:18:51] [LOG] >>>> /Users/wouterdebie/Projects/unwrapper-server/packages/unwrapper-schemas/schemas/json
[13:18:51] [LOG] >>>> /Users/wouterdebie/Projects/unwrapper-server/packages/unwrapper-schemas/schemas/json
[13:18:51] [LOG] >>>> /Users/wouterdebie/Projects/unwrapper-server/packages/unwrapper-schemas/schemas/json
TypeError: Cannot read property 'name' of undefined
so I don't asume we want to ad another package.json file in the subfolder of unwrapper-schemas ? I haven't yet completely understood how the depviz works and thus why it starts processing sub-folder
In version
0.1.0packagesread-pkg-uphas been upgraded from version6.0.0to version7.0.1and it is thus not backwards compatible which results in the error above
I think this is in fact a bug, so well spotted. Not sure how it slipped through the cracks but package on line 88 should be packageJson according to the docs.
As for why it tries to read package.json inside the json folder: are you sure? I think the error about the name property is also what you'd see for the error you originally reported, so that might be the fix?
(Note that this repository is public, so watch out with names like "unwrapper". 😉)
After debugging I noticed following behaviour.
require.context('to_folder/that_is_not_a_package')results in depviz to try to parse it. So I think thus that behaviour is wanted
Fixed in v0.1.1.