FredKSchott / rollup-plugin-polyfill-node

A modern Node.js polyfill for your Rollup bundle.
Other
175 stars 55 forks source link

Does process.cwd() work? #12

Open gavinmcfarland opened 3 years ago

gavinmcfarland commented 3 years ago

Hi, you might already be aware of this. I can't get process.cwd() to work and I'm not sure if there is a missing option I need to pass in for it to work. I can see that it exists in the source code. I think this is probably an issue from rollup-plugin-node-polyfills because it doesn't work in that either.

After setting up rollup and the required plugins it doesn't polyfill process.cwd().

// rollup.config.js

import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import nodePolyfills from 'rollup-plugin-polyfill-node';

export default [{
    input: 'src/index.ts',
    output: {
        file: 'dist/index.js',
        format: 'cjs',
        name: 'code'
    },
    plugins: [
        typescript(),
        nodePolyfills(),
        commonjs()
    ]
}];
// src/index.ts

console.log(process.cwd())
// dist/index.js

'use strict';

console.log(process.cwd());
remorses commented 3 years ago

This plugin only polyfills node native modules, not globals

gavinmcfarland commented 3 years ago

Hi @remorses, so just to confirm it doesn't polyfill process? Because the readme suggests it does.

mattrhysgregory commented 2 years ago

Hi @gavinmcfarland - did you get anywhere with this? facing the same issue

gavinmcfarland commented 2 years ago

It was a while since I looked at it, but I think I did get it working, I remember something about the documentation being hard to understand.

I might have done...

export default [{
    // ...
    plugins: [
        typescript(),
        nodePolyfills({ include: null}),
        commonjs()
    ]
}];

Or I might have passed in {process: true}. The original repo suggests you can turn individual built-ins on and off. https://github.com/ionic-team/rollup-plugin-node-polyfills