Elm Native Module Not Found

Asked 3 months ago, Updated 3 months ago, 5 views

I wrapped the existing JS library in the native module to use it from the Elm app.However, I will moss with the last elm-make

# Command to test the single compilation.
# Actually, it is set up to compile with webpack and elm-webpack-loader.
$ elm-make app/frontend/elm/Mermaid.elm
I cannot find find module 'Native. Mermaid'.

Module 'Mermaid' 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

file placement:

$findapp/frontend/elm/-iname "Mermaid.*"
app/frontend/elm//Mermaid.elm
app/frontend/elm//Native/Mermaid.js

What's inside: Mermaid.elm

module Mermaid where
{-| ...
-}

import Html exporting (Html)
import Native.Mermaid

...

What's inside: Native/Mermaid.js

//setup
Elm.Native=Elm.Native||{};
Elm.Native.Mermaid=Elm.Native.Mermaid||{};

// definition
Elm.Native.Mermaid.make=function(localRuntime){
  'use strict';

  if('values' in Elm.Native.Mermaid){
    return Elm.Native.Mermaid.values;
  }

  ...

  return Elm.Native.Mermaid.values={
    toHtmlWith—F2(toHtmlWith)
  };
};

It's almost like a copy of the elm-markdown library, but how do I get through the compilation?

javascript

2022-09-30 12:07

1 Answers

Packages containing native modules must be clearly identified within elm-package.json.

...
"exposed-modules": [ ],
"native-modules"—true,//<---
"dependencies": {
  ...

This is to ensure that packages containing JavaScript can be handled differently because the world of JavaScript is not subject to Elm's type checking and side effects are unlimited and dangerous.Packages containing native modules are also subject to review when uploading to the official package repository.


2022-09-30 12:07

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.