Solana Anchor Lang: anchor init creates project with TypeError: Cannot read properties of undefined (reading 'methods') - blockchain

Confused about what could have caused this to stop working, I installed solana and anchor and was able to test projects.
anchor --version anchor-cli 0.26.0
nvm use 16.16.0
Now using node v16.16.0 (npm v8.11.0)
anchor init hello-world
yarn install v1.22.19
warning package.json: No license field
info No lockfile found.
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 6.07s.
Initialized empty Git repository in /home/user/Code/anchor-second-test/hello-world/.git/
hello-world initialized
cd hello-world && anchor build works. Making no changes, I run anchor run test
1) hello-world
Is initialized!:
TypeError: Cannot read properties of undefined (reading 'methods')
at /home/user/Code/anchor-second-test/hello-world/tests/hello-world.ts:13:30
at Generator.next (<anonymous>)
at /home/user/Code/anchor-second-test/hello-world/tests/hello-world.ts:31:71
at new Promise (<anonymous>)
at __awaiter (tests/hello-world.ts:27:12)
at Context.<anonymous> (tests/hello-world.ts:11:36)
at processImmediate (node:internal/timers:466:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Here is hello-world.ts test file as generated:
import { Program } from "#project-serum/anchor";
import { HelloWorld } from "../target/types/hello_world";
describe("hello-world", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.AnchorProvider.env());
const program = anchor.workspace.HelloWorld as Program<HelloWorld>;
it("Is initialized!", async () => {
// Add your test here.
const tx = await program.methods.initialize().rpc();
console.log("Your transaction signature", tx);
});
});
I have tried using node lts 16.16.0 instead of the latest lts, starting in a clean directory, checking that typescript was installed, running yarn install before running anchor build command. I checked that the solana keypair and json file was generated in the correct folder.

Go to this ../target/types/hello_world directory and make sure it exports like this
export type HelloWorld = {}
since you have this import
import { HelloWorld } from "../target/types/hello_world";
also, you did not show anchor import . It should be
import * as anchor from "#project-serum/anchor";

Related

Vendoring npm packages in deno

How does one vendor a npm package in deno?
import_map.json:
{
"imports": {
"lume/": "https://deno.land/x/lume#v1.12.1/",
}
}
Lume has some npm dependencies, like https://registry.npmjs.org/markdown-it/-/markdown-it-13.0.0.tgz.
deno.jsonc:
{
"importMap": "import_map.json",
}
dev_deps.ts:
export * as lume from "https://deno.land/x/lume#v1.12.1/mod.ts";
command:
$ deno vendor --force --unstable dev_deps.ts
# ...
Download https://registry.npmjs.org/markdown-it-attrs/-/markdown-it-attrs-4.1.3.tgz
# ...
thread 'main' panicked at 'Could not find local path
for npm:markdown-it-attrs#4.1.3', cli/tools/vendor/mappings.rs:138:11
I tried adding export * as ma from "npm:markdown-it-attrs"; to dev_depts.ts, but it did nothing.
I found the following issue on github.
Maybe this issue does have something to do with it.
I didn't find anything about how to resolve the problem in the official deno documentation and the lume documentation.
Unfortunately, currently you cannot use import_map in your Deno project if your goal is to publish a module that aims to be used in other applications, simply because you don't handle the way deno runtime will start.
From the application point of view, the deno run command cannot search every import_map configurations in your dependencies and handle them properly.
The import_map feature should be used only at end application level.
The fallback is to use by onvention a deps.ts source file to centralize all your dependencies.

adonis issue: error: `migration:run` is not a registered command

I Have installed #adonisjs/lucid.
create a migration to use command
adonis make:migration task
** task code**
'use strict'
const Schema = use('Schema')
class TaskSchema extends Schema {
up() {
this.create('tasks', table => {
table.increments()
table.timestamps()
table.string('name')
table.text('description')
table.integer('project_id').unsigned()
table
.foreign('project_id')
.references('projects.id')
.onDelete('cascade')
})
}
down() {
this.drop('tasks')
}
}
module.exports = TaskSchema
i have run my migration to show this error
error: `migration:run` is not a registered command
**
i have not understand this bug. I know that if not install the
dependencies #adonisjs/lucid than show this error but After I
installed dependencies why the error occurred
**
What you need here is adonis/cli.
npm i -g #adonisjs/cli
But I think the you don't really need this extra dependencies. Using ace is enough
node ace make:migration task
Here is the solution to this question
In fact, I don’t need to install the CLI in production.
Run your server with node server.js and execute internal commands with node ace XXX.
node ace migration:run --force

How to run a specific test with Create React App

In an app create with CRA v.1 I need to run a specific test file. How do I go about it? There is the --testPathIgnorePatterns flag to add to the npm test script to ignore a file or path but how do I run a particular test file with CRA from the command line?
I have done this by using -- to pass custom arguments to the npm script.
Documentation on this option can be found here: https://docs.npmjs.com/cli/run-script
So, to run a single test in a create-react-app application, I run the following:
npm run test -- -t 'test-name'
Where test-name is the value used in the describe function in jest -
describe('test-name', () => {
it('does something', () => { ... });
});
You can use the name of the file in the command, and it will run only it.
For example:
npm test src/App.test.js

Ember serve doesn't work (Error: Couldn't find preset "es2015")

I am building a web app using Ember. I created the project with ember new test-app and have made no changes to the generated files. When I run ember serve, I immediately receive the following error:
The Broccoli Plugin: [BroccoliMergeTrees: Addon#compileAddon(ember-welcome-page) ] failed with:
Error: Couldn't find preset "es2015" relative to directory "/Users/jacob"
at /Users/jacob/Desktop/test-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map ()
at OptionManager.resolvePresets (/Users/jacob/Desktop/test-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/Users/jacob/Desktop/test-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/Users/jacob/Desktop/test-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/Users/jacob/Desktop/test-app/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/jacob/Desktop/test-app/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/jacob/Desktop/test-app/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/jacob/Desktop/test-app/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at Promise (/Users/jacob/Desktop/test-app/node_modules/broccoli-babel-transpiler/lib/parallel-api.js:102:26)
The broccoli plugin was instantiated at:
at BroccoliMergeTrees.Plugin (/Users/jacob/Desktop/test-app/node_modules/broccoli-plugin/index.js:7:31)
at new BroccoliMergeTrees (/Users/jacob/Desktop/test-app/node_modules/ember-cli/node_modules/broccoli-merge-trees/index.js:16:10)
at Function.BroccoliMergeTrees [as _upstreamMergeTrees] (/Users/jacob/Desktop/test-app/node_modules/ember-cli/node_modules/broccoli-merge-trees/index.js:10:53)
at mergeTrees (/Users/jacob/Desktop/test-app/node_modules/ember-cli/lib/broccoli/merge-trees.js:85:33)
at Class.compileAddon (/Users/jacob/Desktop/test-app/node_modules/ember-cli/lib/models/addon.js:1092:12)
at Class.treeForAddon (/Users/jacob/Desktop/test-app/node_modules/ember-cli/lib/models/addon.js:746:26)
at Class.treeForAddon (/Users/jacob/Desktop/test-app/node_modules/ember-welcome-page/index.js:27:41)
at Class.superWrapper [as treeForAddon] (/Users/jacob/Desktop/test-app/node_modules/core-object/lib/assign-properties.js:34:20)
at Class._treeFor (/Users/jacob/Desktop/test-app/node_modules/ember-cli/lib/models/addon.js:557:33)
at Class.treeFor (/Users/jacob/Desktop/test-app/node_modules/ember-cli/lib/models/addon.js:517:21)
I referred to this question for help, but I still received the same error after trying the solution.
I am running ember-cli v2.16.2 and node v8.9.0 on macOS High Sierra. In my node installation, the only three global modules I have installed are bower, broccoli-cli, and ember-cli.
Please do clean reinstall of ember-cli package.
npm uninstall -g ember-cli
npm cache clean --force
npm install -g ember-cli
Then run your ember new command once again and test it.

ember-cli cleanup error when building

I had ember-cli installed on my computer and my app was running perfectly, but yesterday I formatted my computer and upgraded to windows 10 and tried to install ember-cli exactly the same way it was before but now when I try to build or run my application I get this error:
Future versions of Ember CLI will not support v4.2.1. Please update to Node 0.12 or io.js.
version: 1.13.8
Cleanup error.
ENOTEMPTY: directory not empty, rmdir 'C:\Software\company\product\client-side\product2\tmp\concat_with_maps-output_path-jfPUvJvW.tmp'
Error: ENOTEMPTY: directory not empty, rmdir 'C:\Software\company\product\client-side\product2\tmp\concat_with_maps-output_path-jfPUvJvW.tmp'
at Error (native)
at Object.fs.rmdirSync (fs.js:763:18)
at rmkidsSync (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\node_modules\broccoli-caching-writer\node_modules\broccoli-plugin\node_modules\quick-temp\node_modules\rimraf\rimraf.js:247:11)
at rmdirSync (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\node_modules\broccoli-caching-writer\node_modules\broccoli-plugin\node_modules\quick-temp\node_modules\rimraf\rimraf.js:237:7)
at fixWinEPERMSync (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\node_modules\broccoli-caching-writer\node_modules\broccoli-plugin\node_modules\quick-temp\node_modules\rimraf\rimraf.js:150:5)
at Function.rimrafSync [as sync] (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\node_modules\broccoli-caching-writer\node_modules\broccoli-plugin\node_modules\quick-temp\node_modules\rimraf\rimraf.js:216:26)
at Object.remove (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\node_modules\broccoli-caching-writer\node_modules\broccoli-plugin\node_modules\quick-temp\index.js:26:12)
at ReadCompat.cleanup (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\node_modules\broccoli-caching-writer\node_modules\broccoli-plugin\read_compat.js:69:13)
at ConcatWithMaps.Plugin.cleanup (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\node_modules\broccoli-caching-writer\node_modules\broccoli-plugin\index.js:113:49)
at cleanupTree (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli\lib\builder.js:147:17)
Build failed.
ENOENT: no such file or directory, open 'C:\Software\company\product\client-side\product2\tmp\concat_with_maps-input_base_path-QzODcQgu.tmp\0\C:\Software\company\product\client-side\product2\tmp\concat_with_maps-input_base_path-QzODcQgu.tmp\0\ember-basic-dropdown\components\basic-dropdown.js'
Error: ENOENT: no such file or directory, open 'C:\Software\company\product\client-side\product2\tmp\concat_with_maps-input_base_path-QzODcQgu.tmp\0\C:\Software\company\product\client-side\product2\tmp\concat_with_maps-input_base_path-QzODcQgu.tmp\0\ember-basic-dropdown\components\basic-dropdown.js'
at Error (native)
at Object.fs.openSync (fs.js:549:18)
at Object.fs.readFileSync (fs.js:397:15)
at SourceMap.addFile (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\node_modules\fast-sourcemap-concat\lib\source-map.js:68:19)
at ConcatWithMaps.<anonymous> (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\concat-with-maps.js:96:17)
at Array.forEach (native)
at ConcatWithMaps.addFiles (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\concat-with-maps.js:93:9)
at ConcatWithMaps.build (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\concat-with-maps.js:65:8)
at C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\broccoli-sourcemap-concat\node_modules\broccoli-caching-writer\index.js:152:21
at lib$rsvp$$internal$$tryCatch (C:\Software\company\product\client-side\product2\node_modules\ember-cli\node_modules\rsvp\dist\rsvp.js:493:16)
node v4.2.1
npm v2.14.7
But I've tried with others versions and the problem persisted.
The same application is working perfectly on another computer which also has windows 10 and the same node and npm versions.
If you need any extra information leave a comment and I'll edit the question.
I had the same problem today. It seems there's a bug in a dependency module:
"name": "fast-sourcemap-concat",
"version": "0.2.6"
it does not handle properly Windows paths starting with drive letters, like C:/.
For now, I fixed it manually in fast-sourcemap-concat/lib/source-map.js, function _resolveFile, line 55, changing:
if (this.baseDir && filename.slice(0,1) !== '/') {
to:
if (this.baseDir && filename.slice(0,1) !== '/' && filename.slice(1,3) !== ':/') {
Seems to fix the issue for me. Good luck!
This was fixed in https://github.com/ember-cli/ember-cli/issues/5055
You will need to reinstall your node modules:
rm -rf node_modules
npm cache clear
npm install
Try to reinstall Ember CLI in your project directory (local version). You can follow the steps from Ember CLI GitHub releases page - start with rm -rf node_modules bower_components dist tmp and continue following Project Update guide.