Solana Test Program Anchor Test failing tsconfig.json" > needs an import assertion of type "json" - testing

I ran anchor test --skip-deploy and all it should do is initialize my program, but all I get is this error, that I cannot resolve. I checked the tsconfig.json settings they should be fine. This is just the default anchor setup and I'm not importing any unusual JSON files anywhere.
anchor test --skip-deploy BPF SDK:
/Users/julia/.local/share/solana/install/releases/1.9.5/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v cargo-build-bpf child:
cargo +bpf build --target bpfel-unknown-unknown --release warning:
unused variable: ctx --> programs/feeRedeemCounter/src/lib.rs:8:23
| 8 | pub fn initialize(ctx: Context) -> ProgramResult
{ | ^^^ help: if this is intentional, prefix
it with an underscore: _ctx | = note:
#[warn(unused_variables)] on by default
warning: feeRedeemCounter (lib) generated 1 warning
Finished release [optimized] target(s) in 1.28s cargo-build-bpf child:
/Users/julia/.local/share/solana/install/releases/1.9.5/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/llvm-readelf
--dyn-symbols /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/target/deploy/fee_redeem_counter.so
To deploy this program: $ solana program deploy
/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/target/deploy/fee_redeem_counter.so
The program address will default to this keypair (override with
--program-id): /Users/julia/Downloads/anchorTutorial/feeRedeemCounter/target/deploy/fee_redeem_counter-keypair.json
yarn run v1.22.17 warning package.json: No license field $
/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/.bin/ts-mocha
-p ./tsconfig.json -t 1000000 'tests/**/*.ts'
TypeError: Module
"file:///Users/julia/Downloads/anchorTutorial/feeRedeemCounter/tsconfig.json"
needs an import assertion of type "json"
at new NodeError (node:internal/errors:371:5)
at validateAssertions (node:internal/modules/esm/assert:82:15)
at defaultLoad (node:internal/modules/esm/load:24:3)
at ESMLoader.load (node:internal/modules/esm/loader:359:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:58)
at new ModuleJob (node:internal/modules/esm/module_job:66:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:297:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:261:34)
at async Promise.all (index 0)
at ESMLoader.import (node:internal/modules/esm/loader:337:24)
at importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
at formattedImport (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
at Object.exports.requireOrImport (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/nodejs/esm-utils.js:48:32)
at Object.exports.loadFilesAsync (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
at singleRun (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/cli/run-helpers.js:125:3)
at Object.exports.handler (/Users/julia/Downloads/anchorTutorial/feeRedeemCounter/node_modules/mocha/lib/cli/run.js:374:5)
error Command failed with exit code 1. info Visit
https://yarnpkg.com/en/docs/cli/run for documentation about this
command. Error: Program address not found.

I fixed my own problem by running
yarn add ts-mocha

yarn add ts-mocha
This did not work for me. I deleted the package-lock.json and then updated the npm packages to the latest
"devDependencies": {
"#types/chai": "^4.3.4",
"#types/mocha": "^10.0.1",
"#types/node": "^18.11.18",
"chai": "^4.3.7",
"mocha": "^10.2.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.9.5"
then updated the provider code:
import * as anchor from "#project-serum/anchor";
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);

Related

Uniswap v3 Deploy Hardhat Plugin fails - uniswap-v3-deploy-plugin

I have followed along with the deployment steps in https://www.youtube.com/watch?v=cZ7QMmm7hJc for the Hardhat-based Uniswap v3 dev setup.
https://github.com/Uniswap/hardhat-plugin-deploy-v3
In creating a new project:
npm init
npm add --save-dev hardhat
npx hardhat - select create an empty config file
npm install --save-dev #nomiclabs/hardhat-ethers
// add: require("uniswap-v3-deploy-plugin"); to hardhat.config.js
// add: require("#nomiclabs/hardhat-ethers"); to hardhat.config.js
The first issue I encountered was that I had to downgrade Node to v16.3.1.
npx hardhat - i see "deploy-uniswap in the AVAILABLE TASKS
npx hardhat deploy-uniswap results in a nasty error full of bytecode and some additional details:
...3000706000a", code=INVALID_ARGUMENT, version=contracts/5.5.0)
at Logger.makeError (C:\DEV\uniswap-example2\node_modules\#ethersproject\logger\src.ts\index.ts:225:28)
at Logger.throwError (C:\DEV\uniswap-example2\node_modules\#ethersproject\logger\src.ts\index.ts:237:20)
at Logger.throwArgumentError (C:\DEV\uniswap-example2\node_modules\#ethersproject\logger\src.ts\index.ts:241:21)
at new ContractFactory (C:\DEV\uniswap-example2\node_modules\#ethersproject\contracts\src.ts\index.ts:1162:20)
at UniswapV3Deployer.deployContract (C:\DEV\uniswap-example2\node_modules\uniswap-v3-deploy-plugin\src\deployer\UniswapV3Deployer.ts:139:21)
at UniswapV3Deployer.deployPositionDescriptor (C:\DEV\uniswap-example2\node_modules\uniswap-v3-deploy-plugin\src\deployer\UniswapV3Deployer.ts:112:24)
at Function.deploy (C:\DEV\uniswap-example2\node_modules\uniswap-v3-deploy-plugin\src\deployer\UniswapV3Deployer.ts:27:47)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runNextTicks (node:internal/process/task_queues:65:3)
at listOnTimeout (node:internal/timers:526:9) {
reason: 'invalid bytecode',
code: 'INVALID_ARGUMENT',
argument: 'bytecode',
value: '0x60c06040523480156100105760008...
I can't seem to find any other info on this.
There is some breaking change in uniswap/v3-periphery and I solved it by overriding a dependency in the package.json:
"overrides": {
"#uniswap/v3-periphery": "1.0.1"
}
Details about overriding are here.
Try with:
"dependencies": {
"#openzeppelin/contracts": "4.4.2",
"#openzeppelin/contracts-upgradeable": "4.4.2",
"#uniswap/v3-core": "1.0.0",
"#uniswap/v3-periphery": "1.0.1",
"bignumber.js": "9.0.2",
"dotenv": "11.0.0",
"uniswap-v3-deploy-plugin": "0.1.0"
}

Gulpfile problems

enter image description here
enter image description here
I got some problems with my gulpfile. it does`t compile my sass files into css an i have an error (
`Error in plugin "gulp-sass"
Message:
gulp-sass 5 does not have a default Sass compiler; please set one yourself.
Both the `sass` and `node-sass` packages are permitted.
For example, in your gulpfile:
var sass = require('gulp-sass')(require('sass'));
The following tasks did not complete: watch, style
Did you forget to signal async completion?`
) when i try to run it. Browser sync works well enough but i cant compile. I have all modules i need (
"devDependencies": {
"browser-sync": "^2.27.4",
"gulp": "^4.0.2",
"gulp-sass": "^5.0.0"
).

Can't remove `console` statements with babel nor terser in vue cli 3 / 4, but second build run works

I'm having issues with npm run build, which effectively calls vue-cli-service build. My goal is to remove console statements in production builds. However, the first time it fails. If I run it again immediately (without code changes), it succeeds.
For reproducibility and isolation, I'm running code in a node docker:
docker run --rm -it -v "$(pwd):/usr/src/app" node:14.4.0 /bin/bash
In the docker I setup the environment
npm ci
In the clean environment, running the build fails:
root#bd366b5873ca:/usr/src/app# npm run build
> my-app#0.1.0 build /usr/src/app
> vue-cli-service build
PRODUCTION babel setup
production eslint setup.
⠦ Building for production...production eslint setup.
⠇ Building for production...PRODUCTION babel setup
⠼ Building for production...production eslint setup.
⠙ Building for production...
ERROR Failed to compile with 8 errors
The errors are all eslint errors on occurrences of console. commands:
Module Error (from ./node_modules/eslint-loader/index.js):
error: Unexpected console statement (no-console) at XXXX
Immediately running the build again, results in a successful build:
root#bd366b5873ca:/usr/src/app# npm run build
> my-app#0.1.0 build /usr/src/app
> vue-cli-service build
PRODUCTION babel setup
production eslint setup.
⠏ Building for production...
WARNING Compiled with 2 warnings
The PRODUCTION babel setup and production eslint setup originate from my babel.config.js and .eslint.rc.
I've configured eslint as follows, to fail on console. statements in production:
# .eslintrc.js
if (process.env.NODE_ENV === 'production') {
console.info('production eslint setup.')
}
module.exports = {
root: true,
env: {
node: true
},
'plugins': ['jest'],
'extends': [
'eslint:recommended',
'plugin:vue/recommended',
'#vue/standard',
'plugin:jest/recommended',
'plugin:jest/style'
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
},
parserOptions: {
parser: 'babel-eslint',
parserOptions: {
babelOptions: {
configFile: "babel.config.js"
}
}
}
}
I've configured babel to remove the console. statements:
# babel.config.js
/* eslint-disable no-var */
module.exports = (api) => {
var isProd = api.cache.invalidate(() => process.env.NODE_ENV === 'production')
var plugins = []
if (isProd) {
console.info('PRODUCTION babel setup')
plugins.push(['transform-remove-console', { exclude: [] }])
}
return {
presets: ['#vue/cli-plugin-babel/preset'],
plugins
}
}
In attempts to get it fixed, I've also configured terser to remove console. statements:
# vue.config.js
module.exports = {
'transpileDependencies': [
'vuetify'
],
publicPath: process.env.PUBLIC_SUB_PATH === ''
? '/' : '/' + process.env.PUBLIC_SUB_PATH + '/',
runtimeCompiler: true,
css: {
extract: { ignoreOrder: true }
},
chainWebpack: config => {
config.optimization.minimize = true
config.optimization.minimizer('terser').tap((args) => {
args[0].terserOptions.compress.drop_console = true
return args
})
}
}
Versions (from package.json). In attempt to fix it, upgraded to vue-cli 4, also happened in vue-cli 3:
....
"dependencies": {
"axios": "^0.19.2",
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-router": "^3.3.4",
"vuetify": "^2.3.1",
"vuex": "^3.4.0"
},
....
"devDependencies": {
"#babel/core": "^7.10.3",
"#babel/preset-env": "^7.10.3",
"#vue/cli-service": "^4.4.4",
"babel-eslint": "^10.1.0"
"babel-loader": "^8.1.0",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint": "^5.16.0",
...
}
Question:
The console prints of PRODUCTION babel setup and production eslint setup show that in a clean build, the configuration is loaded multiple times. Then it fails somehow. Running it again seems more straightforward, configs are loaded once and then it succeeds.
How can I configure vue to successfully build the first time, removing the console statements?
Is it the cache?
After the successsful build, removing the cache:
rm -Rf ./node_modules/.cache
and then building it again (npm run build) is equal to the first run: fails
Modern build?
When creating a modern build (after a npm run build to populate the cache):
npm run build -- --modern
Successfully builds the legacy build, but fails the modern build:
> my-app#0.1.0 build /usr/src/app
> vue-cli-service build "--modern"
PRODUCTION babel setup
production eslint setup.
⠏ Building legacy bundle for production...
WARNING Compiled with 2 warnings
....
PRODUCTION babel setup
production eslint setup.
⠹ Building modern bundle for production...PRODUCTION babel setup
⠧ Building modern bundle for production...PRODUCTION babel setup
⠋ Building modern bundle for production...PRODUCTION babel setup
⠏ Building modern bundle for production...PRODUCTION babel setup
PRODUCTION babel setup
⠹ Building modern bundle for production...PRODUCTION babel setup
⠧ Building modern bundle for production...PRODUCTION babel setup
⠦ Building modern bundle for production...
ERROR Failed to compile with 3 errors
Module Error (from ./node_modules/thread-loader/dist/cjs.js):
/usr/src/app/src/axios.js
7:3 error Unexpected console statement no-console
Running the modern build again immediately after it succeeds successfully. So I need in total 3 runs for the modern build to succeed (first time legacy bundle fails, second time legacy bundle succeeds but modern build fails, third time legacy and modern build succeed).
Vue issue
There is a related vue issue at https://github.com/vuejs/vue-cli/issues/5399
I met the same err and i fixed it through adding lintOnSave: process.env.NODE_ENV === 'development' in vue.config.js. The following is the checklist to help u fix ur problem:
npx vue-cli-service inspect --mode production >> webpack.config.production.js generate webpack configuration file in production
then you can see lint is before terser. It makes the first time yarn build failure and the next time is successful
so in this case, you can turn off the lintOnSave in production
About lintOnsave

Why does 'vue-cli-service build' fail after creating a new eslint-plugin, with error 'TypeError: eslint.CLIEngine is not a constructor'?

After creating a new eslint-plugin for a custom rule, vue-cli-service build fails (eslint works as expected, when triggered by ./node_modules/.bin/eslint --ext .js,.vue,.json ./ --max-warnings=0).
GitHub repository reproducing issue
Starting in an environment with a working vue-cli-service build, following the simplified instructions at https://blog.webiny.com/create-custom-eslint-rules-in-2-minutes-e3d41cb6a9a0, also reproduces the issue. Running vue-cli-service build after every step, it starts failing after step 4: yarn add --dev file:./eslint, and the build still fails after all the steps are completed.
Error message:
ERROR Failed to compile with 32 errors
Module build failed (from ./node_modules/#vue/cli-plugin-eslint/node_modules/eslint-loader/index.js):
TypeError: eslint.CLIEngine is not a constructor
at Object.module.exports (MYPATH/node_modules/#vue/cli-plugin-eslint/node_modules/eslint-loader/index.js:223:27)
***repeats 31 more times***
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
vue-cli-service build stills fails after running yarn install, which says it is already up to date.
Most results for this specific TypeError: eslint.CLIEngine is not a constructor error claim the user should upgrade their JetBrains IDE. However, I am running vue-cli-service build on the command line and not using JetBrains.
The code referred to by the error message is (with preceding context):
MYPATH/node_modules/#vue/cli-plugin-eslint/node_modules/eslint-loader/index.js
...
var config = assign(
// loader defaults
{
cacheIdentifier: JSON.stringify({
"eslint-loader": pkg.version,
eslint: eslintVersion || "unknown version"
}),
eslintPath: "eslint"
},
userOptions
);
if (typeof config.formatter === "string") {
try {
config.formatter = require(config.formatter);
if (
config.formatter &&
typeof config.formatter !== "function" &&
typeof config.formatter.default === "function"
) {
config.formatter = config.formatter.default;
}
} catch (_) {
// ignored
}
}
var cacheDirectory = config.cache;
var cacheIdentifier = config.cacheIdentifier;
delete config.cacheIdentifier;
// Create the engine only once per config
var configHash = objectHash(config);
if (!engines[configHash]) {
var eslint = require(config.eslintPath);
engines[configHash] = new eslint.CLIEngine(config); //Error happens here
}
...
Edit: I upgraded #vue/cli-plugin-eslint from version 3.11.0 to 4.1.2 by editing yarn's package.json, at the suggestion of #DelenaMalan below. The build still fails with error:
ERROR Failed to compile with 1 errors 7:51:01 PM
Module build failed (from ./node_modules/#vue/cli-service/node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor
at PoolWorker.fromErrorObj (MYPATH/node_modules/#vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:262:12)
at MYPATH/node_modules/#vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:204:29
at mapSeries (MYPATH/node_modules/neo-async/async.js:3625:14)
at PoolWorker.onWorkerMessage (MYPATH/node_modules/#vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:170:35)
at readBuffer (MYPATH/node_modules/#vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:152:14)
at Object.module.exports (MYPATH/node_modules/#vue/cli-plugin-eslint/node_modules/eslint-loader/index.js:223:27)
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR Build failed with errors.
error Command failed with exit code 1.
Edit 2:
I deleted and reinstalled the node modules on the repro linked here, as recommended by #CGundlach, but I still have the eslint.CLIEngine is not a constructor error
Annas-MacBook-Pro:eslint-test-project anna$ rm -rf node_modules/
Annas-MacBook-Pro:eslint-test-project anna$ yarn install
yarn install v1.21.1
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
warning "#vue/eslint-config-airbnb > eslint-import-resolver-webpack#0.11.1" has unmet peer dependency "webpack#>=1.11.0".
[4/4] 🔨 Building fresh packages...
✨ Done in 14.14s.
Annas-MacBook-Pro:eslint-test-project anna$ yarn build
yarn run v1.21.1
$ vue-cli-service build
⠏ Building for production...
ERROR Failed to compile with 1 errors 12:28:32 PM
Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor
at PoolWorker.fromErrorObj (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:262:12)
at /Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:204:29
at mapSeries (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/neo-async/async.js:3625:14)
at PoolWorker.onWorkerMessage (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:170:35)
at readBuffer (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:152:14)
at Object.module.exports (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/eslint-loader/index.js:223:27)
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Make sure all warnings are resolved when you run either npm ci, npm i or yarn install. For me the following warnings were showed after doing a fresh install:
$ vue-cli-service build
⠧ Building for production...
ERROR Failed to compile with 1 error 20:47:55
Syntax Error: Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
When I did a fresh install and resolved the peer dependency issue by decreasing my eslint version everything works as expected.
So try to downgrade your eslint dependency to the correct version. For me I had to downgrade to eslint < 7.0.0.
npm i -D eslint#6.8.0
# or yarn
yarn add -D eslint#6.8.0

Unable to resolve module `stream`

This error starting showing up all of a sudden.
Node : v10.16.3
React native : 0.60.5
react-native-cli: 2.0.1
bundling failed: Error: Unable to resolve module stream from /Users/username/React Native/SampleApp/node_modules/browser-stdout/index.js: Module stream does not exist in the Haste module map
It's giving error for this line :
var WritableStream = require('stream').Writable
I tried installing 'stream' via npm
npm install stream
Then other similar errors started showing up.
One option is to use the client package readable-stream. If dependencies are requiring stream, then i would suggest adding the following to your babel config as well.
yarn add readable-stream
yarn add -D babel-plugin-rewrite-require
babel.config.js
module.exports = {
// rest of config
plugins: [
// other plugins
[
'babel-plugin-rewrite-require',
{
aliases: {
stream: 'readable-stream',
},
},
],
],
};
just install stream using npm install stream and run the project again.