Importing From Chainlink: Source Not Found. File out of allowed directories - visual-studio-code

I have run into this issue multiple times. Everytime I try to import something from github and adding it usign the yarn package manager I am shown with the error below. This time I have been working on a Solidity contract and wanted to import something from the chianlink repository. One workaround I discovered was copying the required files and including them on the project directly but I do not want to do that. So, I wanted a solution to fix this rather than working around it.
I am using the following:
VsCode
WSL 2.0
Hardhat Framework
Yarn Package Manager
So the issue is while I am trying to import:
import "#chainlink/contracts/src/v0.8/VRFV2WrapperConsumerBase.sol";
I am shown:
Source "#chainlink/contracts/src/v0.8/VRFV2WrapperConsumerBase.sol" file outside of allowed directories.
I have already done:
yarn add --dev #chainlink/contracts
Here is my package.json file contents:
{
"devDependencies": {
"#chainlink/contracts": "^0.5.1",
"#nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
"#nomiclabs/hardhat-etherscan": "^3.1.0",
"#nomiclabs/hardhat-waffle": "^2.0.3",
"chai": "^4.3.6",
"dotenv": "^16.0.3",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.7.1",
"hardhat": "^2.11.2",
"hardhat-contract-sizer": "^2.6.1",
"hardhat-deploy": "^0.11.18",
"hardhat-gas-reporter": "^1.0.9",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-beta.24",
"solhint": "^3.3.7",
"solidity-coverage": "^0.8.2"
}
}
Can anyone tell me what might be the cause of this issue? And how to fix it?

Try adding the full relative path to the directory. For example if your directory has a contracts folder and node_module folder and your contract lives within the contracts folder, your import statement for your chainlink contract would look like this:
import "../node_modules/#chainlink/contracts/src/v0.8/VRFV2WrapperConsumerBase.sol";
I have faced this issue a few times and have found this to work.

Related

Lit playground downloaded code don't run locally

I downloaded my-timer files from Lit playground (https://lit.dev/playground/#sample=docs/what-is-lit)
what I found when I unzip the folder:
my-timer.ts
icons.ts
index.html
package.json
downloaded package.json contains below dependencies:
{ "dependencies": { "lit": "^2.0.0", "#lit/reactive-element": "^1.0.0", "lit-element": "^3.0.0", "lit-html": "^2.0.0" } }
I removed the above package.json and added another package.json file suggested by (https://codelabs.developers.google.com/codelabs/the-lit-path#1) VS Code setup section.
here is my new package.json file (https://gist.github.com/e111077/c9d4512dcc35f483abbebf95da24609b)
also added tsconfig.json file as I am getting errors for typescript.
and also added web-dev-server as suggested.
after doing all the above step I run the below command npm run serve, but nothing is on http://localhost:8000/
I don't know what am I missing?
my latest code is here (https://github.com/abhijeet-shelhalkar/my-timer-lit).
please guide me through the right steps.
and what is wrong in my code?

VSCode does not detect import path from node_modules

I have multiple packages installed, such as:
"#testing-library/jest-dom": "^5.11.9",
"#testing-library/react": "^11.2.5",
"#testing-library/react-hooks": "^7.0.2",
when I import like this (* is something exported from these libs):
import * from '#testing-library/jest-dom' // ok, vscode knows this and even auto imports
import * from '#testing-library/react' // vscode doesn't detect this
import * from '#testing-library/react-hooks' // vscode doesn't know what this is
I don't know why because they are added to package.json and installed normally. The code which uses these libraries works 100% fine. The problem is that VSCode cannot work with them, no path auto import, no suggestion, no reference...
Please check if you have installed correct libraries for it or not. If no try to install it or check again in case if you have not installed. If the problem still persists try re-downloading vs code

VScode Solidity extension - not finding openzepplin imports

I'm trying to get started with what should be a very simple Solidity contract but VSCode is giving me a hard time.
I'm using Juan Blancos solidity plugin but VSCode cannot find openzepplin imports
import "#openzeppelin/contracts/token/ERC20/ERC20.sol";
The error is:
Source "#openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported
Even though vscode shows red squigglies I can compile successfully via hardhat compile.
If I change the path to
import "../node_modules/#openzeppelin/contracts/token/ERC20/ERC20.sol";
VScode stops complaining but then I cannot compile via hardhard, with the error being:
Source "node_modules/#openzeppelin/contracts/security/Pausable.sol" not found: File outside of allowed directories.
My VSCode settings for Solidity extension for both User and Workspace are:
"solidity.packageDefaultDependenciesContractsDirectory": "contracts",
"solidity.packageDefaultDependenciesDirectory": "node_modules"
Which corresponds to my project structure
root
|_ contracts
|_ MyToken.sol
|_ node_modules
|_ #openzepplin
I followed the instructions here and have done extensive researching but unfortunately can't get it to working.
Source "#openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported
I had same issue. I had multiple folders added in the unnamed workspace. After removing all other folders and keeping only one project folder resolved issue for me.
Linting issues
If you see something along the lines of:
ParserError: Source "OpenZeppelin/openzeppelin-contracts#3.4.0/contracts/access/Ownable.sol" not found: File not found.
import "#openzeppelin/contracts/access/Ownable.sol";
In your vscode, these and be safely ignored. However you can also add to your settings to ignore these.
Create a .vscode folder at the root of your project.
Create a file called settings.json
Add the following code:
{
"solidity.remappings": [
"#chainlink/=/Users/patrick/.brownie/packages/smartcontractkit/chainlink-brownie-contracts#0.2.2",
"#openzeppelin/=/Users/patrick/.brownie/packages/OpenZeppelin/openzeppelin-contracts#4.3.2"
]
}
Or whatever version your #chainlink and #openzeppelin contracts need. For example:
For more information see here
Use single quotes instead of doubles.
Instead of:
import "#openzeppelin/contracts/token/ERC20/ERC20.sol";
use this:
import '#openzeppelin/contracts/token/ERC20/ERC20.sol';

I am having an issue with babel building angular app for production

Current Behavior
I am building my angular project on circleci and it just keeps failing with the following message:
An unhandled exception occurred: Cannot find module
'#babel/compat-data/corejs3-shipped-proposals'
Require stack:
/home/circleci/eleven-app/frontend/node_modules/#angular-devkit/build-angular/node_modules/#babel/preset-env/lib/polyfills/corejs3/usage-plugin.js
/home/circleci/eleven-app/frontend/node_modules/#angular-devkit/build-angular/node_modules/#babel/preset-env/lib/index.js
/home/circleci/eleven-app/frontend/node_modules/#angular-devkit/build-angular/node_modules/#babel/core/lib/config/files/plugins.js
/home/circleci/eleven-app/frontend/node_modules/#angular-devkit/build-angular/node_modules/#babel/core/lib/config/files/index.js
/home/circleci/eleven-app/frontend/node_modules/#angular-devkit/build-angular/node_modules/#babel/core/lib/index.js
/home/circleci/eleven-app/frontend/node_modules/#angular-devkit/build-angular/src/utils/process-bundle.js
/home/circleci/eleven-app/frontend/node_modules/jest-worker/build/workers/processChild.js
I am using
{
"#babel/plugin-proposal-numeric-separator": "^7.8.3",
"core-js": "3.2.1",
"tslib": "^1.11.1",
"#babel/compat-data": "~7.8.0",
"#babel/runtime-corejs3": "^7.9.2",
"ts-node": "7.0.0",
"tslint": "5.11.0",
"typescript": "3.5.3",
}
resolutions: {
"#babel/preset-env": "^7.8.7"
}
here is npx nls why #babel/preset-env output:
eleven-app-frontend > #angular-devkit/build-angular > #babel/preset-env#7.8.7
eleven-app-frontend > #nrwl/angular > #nrwl/cypress > #cypress/webpack-preprocessor > #babel/preset-env#7.9.5
eleven-app-frontend > #nrwl/cypress > #cypress/webpack-preprocessor > #babel/preset-env#7.9.5
Thank you for reading.
Had the same issue today, so I'm assuming there's something weird with the latest version.
My package.json had the following:
"#babel/compat-data": "~7.9.0"
I removed the ~ to force 7.9.0 instead of allowing newer ones and it did the trick for me.
There's probably a newer version that works but since you opened an issue for them (https://github.com/babel/babel/issues/11427) I'll just wait for more details.
I've the same issue when using TravisCI & Vue with Jest and Babel. My test suit has been failing. Adding "#babel/compat-data": "7.9.0" to devDependencies in my package.json file solved my problems.
These 3 options we came up with so far:
Adapt dependency of babel/preset-env to v7.9.0: "#babel/preset-env": "=7.9.0"
In case you use a NodeJS Docker Image, fix the version to something below 13.13, i.e.: node:13.12.0-alpine
Adding or upgrading "#babel/compat-data": "7.9.0" to devDependencies
The solutions are temporarily and should be removed as soon as there is an actual fix of the node images or the babel/preset-env library.
Linked Github issues:
babel - https://github.com/babel/babel/issues/11427
nodejs - https://github.com/nodejs/node/issues/32852#issuecomment-613652057
I had the same issue today in Github Actions build for a Vue FE project. It builds fine locally. I'm going to try the solution above and I'll report back...
Update: After looking through the package-lock file, my solution was to explicitly add "#babel/compat-data" to the prod dependencies. Previously it was only a dependency for some dev dependencies. So my package.json now looks like:
"dependencies": {
"#babel/compat-data": "^7.8.6",
...
Same issue.
Solved it by following above advices + removing node_modules (see this github thread):
Added explicitly #babel/compat-data": "7.9.0" to devDependencies
Upgraded node (13.3 to 14.0 in my case)
Had to remove my node_modules folder and re run yarn (or npm)
If you're using yarn, try to remove the yarn.lock file in your project. And then reinstall by run yarn install; you'll get a new yarn.lock file, which is fine.
It worked for me in my Next.js project.

Target URI doesn't exist, when trying to import a package in flutter

I have stumbled upon a problem in importing the package in Flutter, I tried to solve this by running flutter packages get and also shutting down the project in Android studio and reopening it.
import 'package:task_02_category_widget/category.dart';
Here is the line above, and the error I'm running into when I run it gives the following error in the console.
Your application could not be compiled, because its dependencies could
not be established.
The following Dart file:
/Users/username/Documents/flutter_rectangle_2/lib/main.dart
...refers, in an import, to the following library:
package:task_02_category_widget/category.dart
That library is in a package that is not known. Maybe you forgot to
mention it in your pubspec.yaml file?
If task_02_category_widget/category.dart is part of an old project you are reusing you should put it in a folder in your flutter application and include it like "../ folder /task_02_category_widget/category.dart ". If it is part of github repository you have copy pasted from, just copy the file and use the step above. Most probably you are looking for that . In any other case check here to find the source code.
You should have in your project at a file called pubspec.yaml a definition like this:
name: my_app
dependencies:
task_02_category_widget:
Let’s say that your package is laid out as follows:
task_02_category_widget/
lib/
category.dart
Then, you can import it:
import 'package:task_02_category_widget/category.dart';
More information:
https://www.dartlang.org/tools/pub/get-started
https://www.dartlang.org/guides/libraries/create-library-packages