Webpack can't import a .json file when using alias / aliased paths - json

I am using Webpack's native json importer to import a json file as a javascript object:
import config from "./config.json"
Works fine - problem is, when I add an alias to the webpack configuration:
resolve: {
alias: {
"#data": path.resolve(__dirname, "src/js/data/"),
},
},
Importing the json file via the aliased path does not seem to work anymore:
import config from "#data/config.json
ERROR in ...
Module not found: Error: Can't resolve '#alias/file.json' in ...
Is there any trick to get Webpack's native json importer to play nice with aliased paths?

I had to add the extensions field to the resolve configuration and include ".json" in the array - after doing that both import config from "#data/config (as the extensions is resolved automatically) and import config from "#data/config.json seem to work fine.

Related

Unable to fetch 0x contract from Etherscan and brownie

I'm trying to test a smart contract which import 0x in brownie ecosystem. I have the following error when importing from explorer or from abi, also it looks like solc doesn't take in count the dependency I've install on my computer
CompilerError: solc returned the following errors:
/home/merklejerk/code/0x-protocol/contracts/zero-ex/contracts/src/external/IFlashWallet.sol:23:1: ParserError: Source "#0x/contracts-utils/contracts/src/v06/interfaces/IOwnableV06.sol" not found: File outside of allowed directories.
import "#0x/contracts-utils/contracts/src/v06/interfaces/IOwnableV06.sol";
^------------------------------------------------------------------------
Probably the compiler does not solve the relative path in the correct way.
Maybe the path of the file you import is wrong or not built properly from the compiler: when importing the file IOwnableV06.sol try to remove the # symbol and replace it with ./ or ../ depending on your project folder structure. For example import "../../0x/the-path-here/File.sol";
Or the file you want to import might not be in the allowed paths:
https://docs.soliditylang.org/en/v0.8.7/using-the-compiler.html#how-it-works
(search for --allow-paths).

jekyll-theme-primer bootsrap.min cannot be found

I am trying to run https://github.com/fossasia/gci18.fossasia.org/ locally.
I did it once with jekyll (on an older version of the site) and it worked.
Now, I cloned it so it is updated, but I cannot get it to work. I keep getting an error message that says
Conversion error: Jekyll::Converters::Scss encountered an error while converting 'css/style.scss':
File to import not found or unreadable: bootstrap.min. Load path: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/jekyll-theme-primer-0.5.3/_sass on line 1
jekyll 3.7.4 | Error: File to import not found or unreadable: bootstrap.min.
Load path: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/jekyll-theme-primer-0.5.3/_sass on line 1
I have tried reinstalling jekyll-theme-primer but it is not working. How can I fix this?
Per the Jekyll Documentation, you'll want to put all of your SCSS partials (such as bootstrap.min.css, themify-icon.css, and the other files imported in /css/style.scss) into the /_sass/ directory for automatic conversion.
Alternatively, you can specify .css in your import statements. For example:
# /css/style.scss
#import 'bootstrap.min.css';
#import 'themify-icon.css';
...
See https://jekyllrb.com/docs/assets/#sassscss for more information.

i create project in angular 6 using angular cli tool but it gives error import * as fs from 'fs';

i create project in angular 6 using angular cli tool but it gives error when i import * as fs from 'fs'(integrate electron app). The error message Module not found: Error: Cannot resolve module 'fs'
I assume you're using node.
Are you using webpack? If so see
here
The solution is to add
node: {
fs: 'empty'
}
to your webpack config.
If that doesn't work, try changing your import statement to a require:
const fs = require('fs');, as the node documentation recommends.

How to import a packge from a local jar in pyspark?

I am using pyspark to do some work on a csv file, hence I need to import package from spark-csv_2.10-1.4.0.jar downloaded from https://repo1.maven.org/maven2/com/databricks/spark-csv_2.11/1.4.0/spark-csv_2.11-1.4.0.jar
I downloaded the jar to my local due to proxy issue.
Can anyone tell me what is the right usage of referring to a local jar:
Here is the code I use:
pyspark --jars /home/rx52019/data/spark-csv_2.10-1.4.0.jar
it will take me to the pyspark shell as expected, however, when I run:
df = sqlContext.read.format('com.databricks.spark.csv').options(header='true',inferschema='true').load('hdfs://dev-icg/user/spark/routes.dat')
the route.dat is uploaded to hdfs already at hdfs://dev-icg/user/spark/routes.dat
It gives me error:
: java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVFormat
If I run:
df = sqlContext.read.format('com.databricks.spark.csv').options(header='true',inferschema='true').load('routes.dat')
I get this error:
py4j.protocol.Py4JJavaError: An error occurred while calling o72.load.
: java.lang.NoClassDefFoundError: Could not initialize class
com.databricks.spark.csv.package$
Can anyone help to sort it out for me? Thank you very much. Any clue is appreciated.
The correct way to do this would be to add the options (say if you are starting a spark shell)
spark-shell --packages com.databricks:spark-csv_2.11:1.4.0 --driver-class-path /path/to/csvfilejar.jar
I have not used the databricks csvjar directly, but I used a netezza connector to spark where they mention using this option
https://github.com/SparkTC/spark-netezza

Importing angular-translate imports an empty object

I'm using JSPM 0.16.42 which uses SystemJS, I've tried both angular-translate and angular-route, both of which are on github endpoints.
However, for both of them angular throws the same error
argument module is not a function
when using them in ES6 syntax as follows:
import AngularRoute from 'angular-route';
angular.module('app', [AngularRoute]);
I'm using babel as a transpiler. The object I get back from the import seems to be empty. Following is the relevant part of my config.js file:
System.config({
baseURL: "/",
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [
"runtime",
"optimisation.modules.system"
]
},
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
map: {
"angular-route": "github:angular/bower-angular-route#1.5.8",
"angular-translate": "github:angular-translate/bower-angular-translate#2.11.1",
}...
EDIT: When I tried to install angular-translate with an npm endpoint I got the error http://errors.angularjs.org/1.5.8/$injector/unpr?p0=e
on the following line in angular.js
return new ErrorConstructor(message);
which I guess is a bit of progress but still doesn't solve my issue obviously
EDIT#2: I got angular-route to work with the help of #artem by using the npm endpoint, for some reason the github endpoint did not work so I used jspm install npm:angular-route. Further investigation is needed as to why the github package did not work and the npm package did
EDIT#3: I have overriden the package configuration as you can see below, though that didn't help
"npm:angular-translate#2.11.1": {
"format": "global",
"dependencies": {
"angular": ">=1.2.26"
},
"shim": {
"angular-translate": {
"deps": "angular"
}
}
}
I eventually fixed it by installing angular-translate as well as angular-route via their npm endpoints instead of the default (github) endpoints, using
jspm install npm:angular-route
&
jspm install npm:angular-translate -o '{dependencies: { angular: ">=1.2.26" } }'
The override for angular-translate was needed since jspm did not understand the original dependency syntax correctly which was angular: ">= 1.2.26 <=1.6" as described in this github issue
Here is not-so-minimal, not-really-self-contained example for angular-translate with systemjs:
npm install jspm
./node_modules/.bin/jspm install github:angular-translate/angular-translate
keep pressing <ENTER>, accepting all the default values
create file test.js
import AngularTranslate from 'angular-translate/angular-translate';
console.log(AngularTranslate);
create file index.html
<!doctype html>
<html>
<head>
<script src="jspm_packages/system.src.js"></script>
<script src="config.js"></script>
<script>
System.import('./test.js');
</script>
</head>
<body>
</body>
</html>
open it in the browser:
Failed to load resource: the server responded with a status of 404 (File not found)
undefined:1 Uncaught (in promise) Error: (SystemJS) XHR error (404 File not found) loading
http://localhost:8035/jspm_packages/github/angular-translate/angular-translate#2.11.1.js(…)
Why that file isn't there? It's supposed to be created by jspm, if you had installed angular-translate from npm it would have contained
module.exports = require("npm:angular-translate#2.11.1/dist/angular-translate.js");
which is just a redirect from symbolic package name (the name of that .js file) to that package main file, as specified in package.json:
"main": "dist/angular-translate.js",
But angular-translate is from github, there is no dist there. That's why jspm did not create the redirect file - there is nothing to redirect to.
No problem, just build it from the source we got from github:
cd jspm_packages/github/angular-translate/angular-translate#2.11.1/
npm install
npm run-script build
cd ../../../..
and fix mapping in config.js:
map: {
"angular-translate/angular-translate": "github:angular-translate/angular-translate#2.11.1/dist/angular-translate",
open index.html in the browser again:
system.src.js:122 Uncaught (in promise) Error: (SystemJS) angular is not defined(…)
No problem, angular is already installed as angular-translate dependency, just tell systemjs when and how to load it.
add to config.js:
meta: {
"angular-translate/angular-translate": {
"deps": ["angular"]
}
},
map: {
"angular": "github:angular-translate/angular-translate#2.11.1/node_modules/angular/angular",
NOTE: You don't need to specify format for angular-translate. SystemJS auto-detects it correctly - it could be loaded as either 'amd' or 'cjs', but it will not work as 'global'. Also, you probably did not start by installing angular-translate, so you already have angular.js file and mapping in place somewhere.
Open index.html in the browser again. It prints in the console:
pascalprecht.translate
Yes angular-translate exports a string - seems to be typical for angular1 modules.
I have no experience with angular.js, so I declare it a success and stop here.
PS Why angular-route worked when you install it from npm, and did not work from github?
When installed from npm, jspm created a file named jspm_packages/npm/angular-route#1.5.8.js, containing
module.exports = require("npm:angular-route#1.5.8/index.js");
because package.json for angular-route has
"main": "index.js",
which is correct and works for you.
When installed from github, jspm created similar file jspm_packages/github/angular/bower-angular-route#1.5.8.js, but this time it points to a different file
module.exports = require("github:angular/bower-angular-route#1.5.8/angular-route");
because someone put an override in jspm registry there at https://github.com/jspm/registry/blob/master/package-overrides/github/angular/bower-angular-route%401.3.0.json
because bower.json for bower-angular-route has
"main": "./angular-route.js",
Maybe it's an oversight, maybe it's correct and works for them - I don't know.
TL;DR It's not a good idea to use package manager for installing software, if the software was not packaged properly for that package manager.