Giter Site home page Giter Site logo

Comments (6)

onigoetz avatar onigoetz commented on July 16, 2024 1

It is similar to #791 but not really

All cases in #791 point on a missing createRequire (which BTW seems to work fine now)

My case is that I have require / createRequire but wish to have import (because what I'm importing is an ESM module)

from ncc.

mr-short avatar mr-short commented on July 16, 2024

I am also running into this issue. Running with sourcemaps also gives ReferenceError: __dirname is not defined in ES module scope. It seems it is still using the global __dirname which you cannot in ESM.

from ncc.

styfle avatar styfle commented on July 16, 2024

This sounds like a duplicate of #749

from ncc.

onigoetz avatar onigoetz commented on July 16, 2024

It is not, #749 mentions wanting to output CJS within an ESM module, and it can't access __dirname / __filename

This is issue is about outputing ESM in an ESM module, and importing other ESM modules.
But NCC's transformations tries to require an ESM module

from ncc.

styfle avatar styfle commented on July 16, 2024

Oops, I meant duplicate of #791

from ncc.

Chocrates avatar Chocrates commented on July 16, 2024

I think I have the same error. I upgraded a package that required me to update my script to be a module so I could use import. Now I can run the script manually just fine, but once I compile it with ncc and try to run it, it fails

file:///home/chris/workspace/chocrates/actions-governance/dist/exec-child.js:1
if (require.main !== module) {
^

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/home/chris/workspace/chocrates/actions-governance/dist/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/chris/workspace/chocrates/actions-governance/dist/exec-child.js:1:1
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
    at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
    at async loadESM (node:internal/process/esm_loader:40:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

There are no require's in my codebase anymore and it looks like the generated exec-child.js is the culprit.

from ncc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.