I want to use v9 branch of elm-mdl library.
I added native-modules to true in my elm-package.json and added external\elm-mdl to my source-directories list.
I then added "debois/elm-mdl": "9.0.0 <= v < 10.0.0", to elm-package.json
I ran elm-install but it complains about :
▶ No solution found: Unable to satisfy the following requirements:
- `debois/elm-mdl (< 10.0.0)` required by `user-specified dependency`
- `debois/elm-mdl (>= 9.0.0)` required by `user-specified dependency`
How can i make elm-install and elm-make to pick up my cloned directory version of the library ?
Please see directory structure and elm-package.json output below :
└─ $ ▶ elm --version
0.18.0
└─ $ ▶ cat elm-package.json
{
"version": "1.0.0",
"summary": "Track your life.",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"native-modules": true,
"source-directories": [
"src",
"external/elm-mdl"
],
"exposed-modules": [],
"dependencies": {
"danyx23/elm-uuid": "2.1.0 <= v < 3.0.0",
"debois/elm-mdl": "9.0.0 <= v < 10.0.0",
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"mgold/elm-random-pcg": "4.0.2 <= v < 6.0.0",
"rtfeldman/elm-css": "9.1.0 <= v < 10.0.0",
"rtfeldman/elm-css-helpers": "2.1.0 <= v < 3.0.0",
"sporto/elm-dropdown": "1.3.0 <= v < 2.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
└─ $ ▶ cat external/elm-mdl/elm-package.json
{
"version": "9.1.0",
"summary": "Material Design Lite port to Elm",
"repository": "https://github.com/debois/elm-mdl.git",
"license": "Apache License, version 2.0",
"source-directories": [
"src"
...
└─ $ ▶ ls external/elm-mdl/
build_scripts CONTRIBUTING.md COPYING.md demo elm-package.json examples FAQ.md foo.md LICENSE.md Makefile MIGRATION.md PR.md README.md RELEASE.md src TEMPLATES.md TESTING.md tests USERS.md
ashish # 7567 ~/work/be_autonomous (master)
└─ $ ▶ ls
Architecture.md compile_css.sh elm-package.json elm-stuff external index.css index.html index.js run.sh src TAGS tests
Here's an answer I prepared earlier: Using local packages
In summary, remove the elm-mdl reference in your dependencies and link to the folder where the Material module is defined, ie:
"source-directories": [
-- ADD src because Material.elm is under that folder
"external/elm-mdl/src"
],
"dependencies": {
-- REMOVE LINE BELOW
"debois/elm-mdl": "9.0.0 <= v < 10.0.0",
},
It will then error for every package that elm-mdl depends on, add them locally as per the SO link I referenced above.
Related
Following folder structure and files are given:
.
├── package.json
└── scripts
├── hello-word.js
└── package.json
// package.json
{
"name": "yarn-bin",
"version": "1.0.0",
"private": true,
"license": "ISC",
"workspaces": [
"scripts"
]
}
// scripts/package.json
{
"name": "#yarn-bin/scripts",
"version": "1.0.0",
"license": "ISC",
"bin": {
"hello-world": "./hello-world.js"
}
}
// scripts/hello-world.js
#!/usr/bin/env -S npx node
console.log("Hello World")
This is a very simple yarn workspace setup where an executable is specified in a workspace package ("bin" in scripts/package.json).
Executing ./hello-world.js works just fine (with prior chmod +x hello-world.js).
Question
Is it possible to install this executable in the workspace itself?
(To break it down: I would like to execute the script from anywhere in the workspace e.g. with npx hello-world)
Like I said in the comments what you got here is almost complete.
You did have a typo in your file name but I assume that's a typo that happened while you copied this over to SO.
I did change the hash bang to make sure you run this via node.
You cannot run this via npx as npx will go online and look through the registry.
.
├── package.json
└── scripts
├── hello-world.js # not "hello-word.js"
└── package.json
Root package.json:
{
"name": "yarn-bin",
"version": "1.0.0",
"private": true,
"license": "ISC",
"scripts": {
"hello": "yarn hello-world"
},
"workspaces": [
"scripts"
]
}
scripts/package.json
{
"name": "#yarn-bin/scripts",
"version": "1.0.0",
"license": "ISC",
"bin": {
"hello-world": "./hello-world.js"
}
}
And script/hello-world.js
#!/usr/bin/env node
console.log("Hello World")
With that setup running yarn hello in the root folder will yield:
$ yarn hello
yarn run v1.22.10
$ yarn hello-world
$ /path/to/folder/node_modules/.bin/hello-world
Hello World
✨ Done in 0.25s.
While I added an npm script into the root package.json you can also execute bins via just running yarn hello-world anywhere from within your project.
Background
I'm an absolute beginner in BuckleScript, and while I've downloaded packgages with npm before, I've never written a library.
Goal: installing my new package local package in my project using npm
I am trying to wrap some parts of the service worker api in JavaScript. I have started with a file bs-service-worker/src/ExtendableEvent.re like so
type _extendableEvent('a);
type extendableEvent_like('a) = Dom.event_like(_extendableEvent('a));
type extendableEvent = extendableEvent_like(Dom._baseClass);
[#bs.send] external waitUntil: (extendableEvent, Js.Promise.t('a)) => unit
= "waitUntil";
This compiles and produces ExtendableEvent.bs.js as expected.
Now, though, I'd like to go ahead and test what I have so far by creating a new npm project and importing what I have locally. I created a new sibling directory and did an npm install ../bs-service-worker. That succeeded, and then I did a sanity-check build on my new BuckleScript project. That also succeeded.
The issue: opening my module causes an error
When I add open ExtendableEvent; to Demo.re in the new project, I get the following error:
We've found a bug for you!
/home/el/workbench/bucklescript/bs-service-worker-examples/src/Demo.re 11:6-20
9 │
10 │ /**/
11 │ open ExtendableEvent;
12 │
13 │ /*
The module or file ExtendableEvent can't be found.
- If it's a third-party dependency:
- Did you list it in bsconfig.json?
- Did you run `bsb` instead of `bsb -make-world`
(latter builds third-parties)?
- Did you include the file's directory in bsconfig.json?
What I've tried
I'm guessing I'm misusing BuckleScript here instead of npm because npm is so widely adopted and well documented that I think I'd have found the problem, but I'm definitely not ruling out the possibility that I'm misusing npm, too.
I do have "bs-service-worker" listed as a bs-dependency. I also tried "../bs-service-worker" in case BuckleScript didn't like the virtual directory, but it didn't seem to help.
My npm run build command is indeed npx bsb -make-world.
More code:
bs-service-worker/bs-config.json
{
"name": "bs-service-worker",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true,
"public": "all"
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
],
"warnings": {
"error" : "+101"
},
"namespace": true,
"refmt": 3
}
bs-service-worker-examples/bsconfig.json
{
"name": "bs-service-worker-examples",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [
"bs-service-worker",
"bs-fetch",
],
"warnings": {
"error" : "+101"
},
"namespace": true,
"refmt": 3
}
bs-service-worker-examples/package.json
{
"name": "bs-service-worker-examples",
"version": "0.0.1",
"scripts": {
"build": "npx bsb -make-world",
"start": "npx bsb -make-world -w",
"clean": "npx bsb -clean-world"
},
"keywords": [
"BuckleScript"
],
"author": "Eleanor (https://webbureaucrat.bitbucket.io)",
"license": "MIT",
"devDependencies": {
"bs-platform": "^7.3.2"
},
"dependencies": {
"bs-fetch": "^0.6.1",
"bs-service-worker": "file:../bs-service-worker"
}
}
Easy Reproduction of the Issue
The fastest way to reproduce this would be to fork this repository and try to add it as a local npm dependency.
The problem seems to be that you have "namespace": true in your library's bsconfig.json, which will wrap all the modules in a namespace module with a silly generated name based on the name field. In this case it will be BsServiceWorker I think.
You could just remove that setting, or set it to false, but namespacing is a good idea to avoid collisions between modules from different libraries, or your own app, so I would recommend setting it to a custom, sensible name. For example:
"namespace": "ServiceWorker"
You can then open ExtendableEvent in the consumer project with:
open ServiceWorker.ExtendableEvent;
For more details, see the documentation on the namespace field.
I am attempting to create an Elm project in Intellij. To do this, I am using a fairly standard elm-package.json fle:
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
I am trying to load this project, and am getting the following failure:
org.elm.workspace.ProjectLoadException: The 'type' field is 'null', but expected either 'application' or 'package'
There does not seem to be any documentation of this 'type' field! What is it? Where do I place it? More importantly, why wasn't it generated with the rest of the json file when I created it using elm-package install???
Here is my project's elm-package.json
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"simonh1000/elm-charts": "3.1.0 <= v < 4.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
elm-charts exports a module called Chart.
In my ChartView.elm I want to import Chart
module Components.ChartView exposing ( .. )
import Chart as C exposing ( .. )
import Html exposing ( Html, div )
import Html.Attributes exposing ( id, class )
but when elm tries to compile, I get the error:
I cannot find module 'Chart'.
Module 'Components.ChartView' is trying to import it.
Potential problems could be: * Misspelled the module name * Need
to add a source directory or new dependency to elm-package.json
if I open elm repl from the project directory, I can import Chart as expected:
jon#jon-Xubuntu-VB:~/elixir/eval$ elm repl
\> import Chart
\>
any ideas why I Elm can't 'find Chart' when compiling?
Though this has been resolved in comments, no one has written this in an answer yet.
Elm will not find dependencies from nested directories: you want to run elm repl in the same directory as your elm-package.json (adjacent to the elm-stuff directory). It sounds like you mistakenly have an elm-package.json file at the top level of your app, when you wanted it in the web/elm/ directory.
I compiled the "Hello world" program
import Html exposing (text)
main =
text "Hello, World!"
with elm 0.17 on Windows, without compile errors:
elm make hello.elm --output index.html
When I open Chrome on index.html, I get a blank page. Chrome's console shows 2 errors in index.html :
Uncaught ReferenceError: _elm_lang$virtual_dom$VirtualDom$text is not defined
Uncaught ReferenceError: Elm is not defined
If I run the elm-reactor on that file, I also get a white page, and similar errors in the console.
Somehow, a path is missing... Here is the elm-package.json file:
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/html": "1.0.0 <= v < 2.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
}
What should I do ?
I fixed it by deleting the elm-stuff subdirectory. At the next make, it reinstalls the missing packages, and everything works fine.