Fails with complex usage scenario with `commonjs` and POSIX paths
See original GitHub issueApologies for not breaking this down to a minimal reproduction case, but I don’t have time right now and I thought you might be interested in the issue even without the full repro, and that you might understand what the fundamental issue is.
I have a pretty complex Rollup configuration:
module.exports = {
entry: 'src/host/main.ts',
dest: 'int/js/mainout.js',
exports: "none",
external: [
"bluebird",
"power-assert"
],
globals: {
"bluebird": "Promise",
"power-assert": "assert"
},
useStrict: true,
sourceMap: true,
format: "iife",
plugins: [
json(),
typescript({
typescript: require('typescript'),
}),
nodeResolve({
// use "jsnext:main" if possible
// – see https://github.com/rollup/rollup/wiki/jsnext:main
jsnext: true, // Default: false
// use "main" field or index.js, even if it's not an ES6 module
// (needs to be converted from CommonJS to ES6
// – see https://github.com/rollup/rollup-plugin-commonjs
main: true, // Default: true
// if there's something your bundle requires that you DON'T
// want to include, add it to 'skip'
skip: [], // Default: []
// some package.json files have a `browser` field which
// specifies alternative files to load for people bundling
// for the browser. If that's you, use this option, otherwise
// pkg.browser will be ignored
browser: true, // Default: false
// not all files you want to resolve are .js files
extensions: [ '.js', '.json', '.ts' ], // Default: ['.js']
sourceMap: true,
// whether to prefer built-in modules (e.g. `fs`, `path`) or
// local ones with the same names
preferBuiltins: false // Default: true
}),
commonjs({
extensions: [ '.js', '.ts' ],
namedExports: {
"javascript-astar": [ "Graph", "astar" ],
"screenfull": [ "request" ],
"marked": ["Renderer","setOptions","parse"],
}
}),
buble({transforms: { dangerousForOf: true, dangerousTaggedTemplateString: true }})
]
};
This (mostly) works with the rollup-plugin-typescript
plugin, but I thought I’d try this variant of the plugin instead. In part I wanted to try this because the last step above – buble
– is not processing the TypeScript helpers injected by rollup-plugin-typescript
. Since you’re doing something different, I thought that issue might be solved by switching to this plugin.
But when I switch my include to rollup-plugin-typescript2
, I get an error:
Failed to build client-js: Error: Module C:/Users/tim/projects/games/steel/node_modules/javascript-astar/astar.js does not export astar (imported by C:/Users/tim/projects/games/steel/src/common/pathhelper.ts)
at Module.trace (C:\Users\tim\projects\games\steel\node_modules\rollup\dist\rollup.js:6432:29)
at C:\Users\tim\projects\games\steel\node_modules\rollup\dist\rollup.js:6006:32
...
This doesn’t even look like it’s in your code, but it doesn’t happen when I run the code through the older plugin, and I don’t have the time to dig down to the root cause here, so I need to fall back on the older plugin. Looking at the TypeScript options you’re setting:
noEmitHelpers: true,
importHelpers: true
… I thought one of these might be causing the problem, but no, when I set those it works using the old plugin. Not only that, but it fixes the problem I was having (because TypeScript is now using the imported helpers which buble correctly).
I have a TypeScript declaration file for javascript-astar
, but honestly what it looks like is happening above is not a TypeScript bug but some kind of interaction problem between this plugin and the commonjs
plugin (where I specify explicit exports for javascript-astar
).
So if I were you and wanted to test this, I’d get an example together that imports some raw JavaScript using the node-resolve
and commonjs
plugins and see how rollup-plugin-typescript2
might be breaking commonjs
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (7 by maintainers)
Top GitHub Comments
That warning means there are cycles in import tree, not necessarily dependency cycles (not sure how useful the warning is, since modules can import and export multiple things and not all at once). So it is probably unrelated. I have it in my own code too for what its worth.
This looks like it could best be fixed in commonjs itself. I opened https://github.com/rollup/rollup-plugin-commonjs/issues/177 and left the hack turned off by default for now. In 0.2.2 now.
Thanks for figuring it out. 😃
OK, grabbed master and now I get this:
But at least it seems to work. 🤷. Maybe that warning is a hint as to why things are different?