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

load mjs files as javascript/auto #3906

Closed
wants to merge 1 commit into from
Closed

Conversation

aldarund
Copy link

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Resolves #3892

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests passed.

@pi0
Copy link
Member

pi0 commented Sep 17, 2018

I think mjs spec strictly forbids use of require. Maybe we can offer users to extend webpack config instead of changing it to something non standard. Or Simply they can use js if require is needed.

@pi0
Copy link
Member

pi0 commented Sep 17, 2018

Another note: We don't know what optimization and behavior would webpack have for mjs type in the future. If we behave .mjs as js/auto (Same as js) then what's the point of setting mja extension instead of js?

@aldarund
Copy link
Author

aldarund commented Sep 17, 2018

@pi0 there no require in the mjs file itself. But it endsup in generated code.

 function(e, t, n) {
    "use strict";
    (function(e) {
        t.a = function(e, t) {
            return e instanceof t
        }
    }
    ).call(this, require("./../../process/browser.js"))
}

And its ends up in browser error on page load, not a compile time error

Fix was stolen from here : aws-amplify/amplify-js#686 (comment)

Copy link
Member

@clarkdo clarkdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pi0 is correct, webpack now is using javascript/esm for .mjs file, it's more strictly, dynamic modules (non-esm, i. e. CommonJs) can only imported via default import, everything else (including namespace import) emit error

If we use javascript/auto, .mjs functionality will be limited, because it will be treated as a js and lost the .mjs features (Although it's still WIP) 😄

@aldarund
Copy link
Author

aldarund commented Sep 17, 2018

@clarkdo @pi0 digged a bit deeper, ye, you are right. Im not sure why and how issue with nuxt/apollo happens because i dont see any require inside graphql mjs files. But updating graphql to 14 fixes the problem. Il open a pr to vue-cli-appollo-plugin with version bump then :)

@aldarund aldarund closed this Sep 17, 2018
@lock
Copy link

lock bot commented Oct 31, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 31, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[edge] Uncaught ReferenceError: require is not defined when using @nuxtjs/apollo
4 participants