Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for PureScript 0.15 #3

Closed
wants to merge 7 commits into from
Closed

Update for PureScript 0.15 #3

wants to merge 7 commits into from

Conversation

thomashoneyman
Copy link
Collaborator

No description provided.

@thomashoneyman
Copy link
Collaborator Author

I'm struggling to pin down where exactly the source of this problem is:

➜ spago test
[info] Build succeeded.
Main...

file:///home/trh/Desktop/purescript-node-workerbees/output/Effect.Aff/foreign.js:530
                throw util.fromLeft(step);
                ^
[worker eval]:1
import { worker } from "/home/trh/Desktop/purescript-node-workerbees/output/Test.Main/index.js;
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at new Script (node:vm:100:7)
    at createScript (node:vm:257:10)
    at Object.runInThisContext (node:vm:305:10)
    at node:internal/process/execution:76:19
    at [worker eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:75:60)
    at MessagePort.<anonymous> (node:internal/main/worker_thread:180:7)
    at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:643:20)
    at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28)
[error] Tests failed: exit code: 1

I'd expect this to come from somewhere something like node -e <contents> was being called, but I'm struggling to track this all the way down.

@natefaubion
Copy link
Owner

It's probably coming from jsEval.

@thomashoneyman
Copy link
Collaborator Author

Without touching those lines (ie. leaving them as require, I get:

➜ node -e 'const Main = require("./output/Test.Main/index.js"); main();'
node:internal/modules/cjs/loader:1156
      throw err;
      ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/trh/Desktop/purescript-node-workerbees/output/Test.Main/index.js from /home/trh/Desktop/purescript-node-workerbees/[eval] not supported.
Instead change the require of index.js in /home/trh/Desktop/purescript-node-workerbees/[eval] to a dynamic import() which is available in all CommonJS modules.
    at [eval]:1:14
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at [eval]-wrapper:6:22 {
  code: 'ERR_REQUIRE_ESM'
}

The Node docs are all still using require(); I'm not sure how to convert it to ES modules, or if that's impossible, how to have the two module types play nicely together. I'll dig for now, but if you have advice I'm all ears.

@natefaubion
Copy link
Owner

Maybe you can pass in --input-type=module via argv or execArgv options?

@natefaubion
Copy link
Owner

You might have to use data URIs instead. nodejs/node#30682 (comment)

@thomashoneyman
Copy link
Collaborator Author

Ah, I forgot to mention I did try passing the flag via both argv and execArgv, but it didn't have any effect.

@thomashoneyman
Copy link
Collaborator Author

You might have to use data URIs instead. nodejs/node#30682 (comment)

This looks promising! I've got to run, but when I get back online I'll try it out.

@thomashoneyman
Copy link
Collaborator Author

Progress update: switching to a data url does indeed allow progress, but now I'm getting another failure:

Main...

file:///home/trh/Desktop/purescript-node-workerbees/output/Effect.Aff/foreign.js:530
                throw util.fromLeft(step);
                ^
TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
    at new NodeError (node:internal/errors:372:5)
    at fileURLToPath (node:internal/url:1422:11)
    at checkIfDisallowedImport (node:internal/modules/esm/resolve:1061:23)
    at defaultResolve (node:internal/modules/esm/resolve:1189:23)
    at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_INVALID_URL_SCHEME'
}
[error] Tests failed: exit code: 1

As usual, advice is appreciated, but I'll continue sleuthing!

@thomashoneyman
Copy link
Collaborator Author

I'm stumped -- even when the eval is just:

import * as worker from "file:///home/trh/Desktop/purescript-node-workerbees/output/Test.Main/index.js";

...the error output is TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file. Evaluating something else instead, like:

console.log("hello");

...works just fine, but obviously nothing has been imported.

@thomashoneyman
Copy link
Collaborator Author

@natefaubion I've removed the make function altogether as I couldn't get it working with imports. The updated tests show how it must be used (unsafely) until that can be resolved.

@natefaubion
Copy link
Owner

I think this looks good, but we should push it to a separate branch, not main.

@thomashoneyman
Copy link
Collaborator Author

node-esm

@thomashoneyman thomashoneyman deleted the trh/purs-0.15 branch May 13, 2022 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants