Error ... Cannot find package 'visitor-as'
Steps to reproduce:
- In a new empty directory, create a new AssemblyScript project .
- Run
npm run asbuild- it should compile without error - Run
npm install json-as - Modify
asconfig.jsonto add"transform": ["json-as/transform"]to the existingoptionssection - Run
npm run asbuildagain - it fails with:
FAILURE Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'visitor-as' imported from /<projectdir>/node_modules/json-as/transform/lib/index.js
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at packageResolve (node:internal/modules/esm/resolve:890:9)
at moduleResolve (node:internal/modules/esm/resolve:939:20)
at defaultResolve (node:internal/modules/esm/resolve:1132:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36)
Tried manually installing with npm install visitor-as --save-dev, but that gives:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/assemblyscript
npm ERR! dev assemblyscript@"^0.27.14" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer assemblyscript@"^0.25.0" from [email protected]
npm ERR! node_modules/visitor-as
npm ERR! dev visitor-as@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
It does work if I use --force, but I shouldn't have to do that.
Not sure if this is a problem with as-json, or with visitor-as, or both.
Thanks.
To clarify, if I use --force or --legacy-peer-deps, it adds visitor-as to the devDependencies section correctly, but future calls to npm install (such as on a fresh clone of my project repo) still fail with the same message.
As a workaround, this seems to do the trick:
{
"dependencies": {
"json-as": "^0.5.65"
},
"devDependencies": {
"assemblyscript": "^0.27.14",
"visitor-as": "^0.11.4"
},
"overrides": {
"assemblyscript": "$assemblyscript"
}
}
With that override, now my npm install works without giving an error.
Got it. Yeah that's just how NPM works sometimes and is a problem with visitor-as' deps
Resolved. Json-as now ships with its own visitor