question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

import of Standalone module in ESM module requires using .default property

See original GitHub issue

What version of Ajv are you using? Does the issue happen if you use the latest version? v8.6.2

Your code Sandbox

import Ajv from "ajv";
import standalone from "ajv/dist/standalone/index.js";
const ajv = new Ajv();
const validate = ajv.compile({ type: "number", maximum: 5 });

const schema_compiler: string = standalone(ajv, validate);

Validation result, data AFTER validation, error messages

TypeError: standalone is not a function
    at file:///sandbox/src/index.ts:6:13
    at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)

What results did you expect? I should be able to import standalone module without using .default property

Are you going to resolve the issue? This one is very similar to #1381. If required, I can create a PR to add module.exports = exports = standaloneCode for lib/standalone/index.ts

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
epoberezkincommented, Sep 12, 2021

thank you! There was some incompatible typescript change I know fixed.

1reaction
bhvngtcommented, Sep 10, 2021

Cool. I have raised #1757 with the changes. My changes are consistent with what was done to fix #1381. CI seems to be failing for the PR and I don’t understand the reason why it is failing. Same tests when I run locally passes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building CJS module from ESM with mixed named and default ...
I am trying to configure rollup to build commonjs module from existing esm. I have set of separate standalone methods, exported with default...
Read more >
Using ES Modules (ESM) in Node.js: A Practical Guide (Part 1)
This guide shows you how to use ESM in Node.js, detailing the basics, ... when importing CJS modules, you can only use “default”...
Read more >
Standalone validation code - Ajv JSON schema validator
The standalone code can be generated in either CJS (module.export & require) or ESM (exports & import), it defaults to CJS. Set the...
Read more >
import() which is available in all commonjs modules. - You.com
taskRepository: Failed to require task module for setTimestamp: require() of ES ... but translates CommonJS modules into modules with a default property:.
Read more >
Getting started with standalone components - Angular
@Component({ standalone: true, selector: 'photo-gallery', // an existing module is imported directly into a standalone component imports: [MatButtonModule], ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found