Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

"name-is-not-exported-by-module" for default export #206

Closed
gcharnock opened this issue Jul 3, 2017 · 6 comments
Closed

"name-is-not-exported-by-module" for default export #206

gcharnock opened this issue Jul 3, 2017 · 6 comments

Comments

@gcharnock
Copy link

I'm attempting to use rollup for the first time, and I've encountered errors that look like "Error: 'foo' is not exported by node_modules/fast-json-patch/src/json-patch-duplex.js" a few times. The advice suggested by the error message has generally worked.

https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module

However, what do I do when the object I want is the default export from the module? I've tried:

namedExports: {
    "node_modules/fast-json-patch/src/json-patch-duplex.js": ["default"]
}

Though I wan't really expecting the above to work (what if the module exported a non-default property called "default"?) and it didn't. I'm not sure what to do.

I'm sorry if this turns out to be a stupid question. All the previous "modern" javascript I've done has been server side. I'm finding all the seemingly countless module systems extremely confusing.

@fregante
Copy link

fregante commented Jul 4, 2017

This is a recurring issue. Take a look at the existing issues to hopefully find a solution.

@gcharnock
Copy link
Author

gcharnock commented Jul 4, 2017

So I was able to find this #186, but the suggested answer doesn't work any more:

    Error: options.skip is no longer supported — you should use the main Rollup `externals` option instead

So I tried "external" in the main options

    external: ["fast-json-patch"],

This does compile, but fails at runtime.

require.js:168 Uncaught Error: Script error for "fast-json-patch", needed by: benchmark-standalone

(Note that I had a requirejs available on my page, otherwise I assume the error would be something like require is not defined). So I need to find a cdn version of fast-json-patch in AMD format.

Edit: Or just forgo the import completely and just use the jsonpatch from the global scope.

@dead-claudia
Copy link

I found this particular issue, and it proposed changing mod['default'] to mod['def' + 'ault'] as a fix.

@awerlang
Copy link

Instead of import myModule from 'my-module'; try using import myModule from 'node_modules/my-module/dist/my-module.js'.

@otolab
Copy link
Contributor

otolab commented Oct 13, 2017

I think "def"+"ault" is too hacky, so I tried write it in other ways, PR #243.

It checked whether exporting "default" by AST, switch commonjs-proxy code by with / without "default".

Maybe processing cost increase slightly but that way is better.

@shellscape
Copy link
Contributor

Hey folks (this is a canned reply, but we mean it!). Thanks to everyone who participated in this issue. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one, but it doesn't mean that it's not still valid. We've got some time yet before the move while we resolve pending Pull Requests, so if this issue is still relevant, please @ me and I'll make sure it gets transferred to the new repo. 🍺

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants