Skip to content

Error when dealing with multiple exports #950

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

Open
CMCDragonkai opened this issue Nov 10, 2017 · 8 comments
Open

Error when dealing with multiple exports #950

CMCDragonkai opened this issue Nov 10, 2017 · 8 comments

Comments

@CMCDragonkai
Copy link

CMCDragonkai commented Nov 10, 2017

I get this error on 5.3.3:

Error: Parsing file C:\Users\CMCDragonkai\Projects\js-virtualfs\lib\index.js: 'import' and 'export' may appear only with 'sourceType: module' (3:0)
    at Deps.parseDeps (C:\Users\CMCDragonkai\Projects\js-virtualfs\node_modules\module-deps-sortable\index.js:467:28)
    at fromSource (C:\Users\CMCDragonkai\Projects\js-virtualfs\node_modules\module-deps-sortable\index.js:402:44)
    at C:\Users\CMCDragonkai\Projects\js-virtualfs\node_modules\module-deps-sortable\index.js:396:17
    at ConcatStream.<anonymous> (C:\Users\CMCDragonkai\Projects\js-virtualfs\node_modules\module-deps-sortable\node_modules\concat-stream\index.js:36:4
3)
    at emitNone (events.js:91:20)
    at ConcatStream.emit (events.js:185:7)
    at finishMaybe (C:\Users\CMCDragonkai\Projects\js-virtualfs\node_modules\module-deps-sortable\node_modules\concat-stream\node_modules\readable-stre
am\lib\_stream_writable.js:475:14)
    at endWritable (C:\Users\CMCDragonkai\Projects\js-virtualfs\node_modules\module-deps-sortable\node_modules\concat-stream\node_modules\readable-stre
am\lib\_stream_writable.js:485:3)
    at ConcatStream.Writable.end (C:\Users\CMCDragonkai\Projects\js-virtualfs\node_modules\module-deps-sortable\node_modules\concat-stream\node_modules
\readable-stream\lib\_stream_writable.js:455:41)
    at DuplexWrapper.onend (C:\Users\CMCDragonkai\Projects\js-virtualfs\node_modules\readable-stream\lib\_stream_readable.js:570:10)

When running documentation build ./lib/** -f html -o ./doc on a lib/index.js:

//@flow
export { default } from './VirtualFSSingle.js';
export { default as VirtualFS } from './VirtualFS.js';
export { default as Stat } from './Stat.js';
export { default as constants } from './constants.js';
export { default as nullDev } from './Devices/null.js';
export { default as zeroDev } from './Devices/zero.js';
export { default as fullDev } from './Devices/full.js';
export { default as randomDev } from './Devices/random.js';
export * from './VirtualFSError.js';
export * from './Devices.js';
export * from './INodes.js';
export * from './FileDescriptors.js';
export * from './Streams.js';
export * from './permissions.js';

// polyfills to be exported
// $FlowFixMe: Buffer exists
export { Buffer } from 'buffer';
export { nextTick } from 'process';

Full project https://github.com/MatrixAI/js-virtualfs

@tmcw
Copy link
Member

tmcw commented Nov 15, 2017

Previously: #483 - this remains an elusive bug, reported often in babelify, most recently in babel/babelify#186 - maybe one of the comments on that issue helps you find a fix?

@CMCDragonkai
Copy link
Author

CMCDragonkai commented Nov 16, 2017

I don't use browserify (and by extension I think that means babelify).

This is purely caused by index.js, when I don't have it that way (multiple exports), there's no problem.

@CMCDragonkai
Copy link
Author

CMCDragonkai commented Nov 16, 2017

So I've isolated the problem even further. It is exactly the: export * from '...' statements that are causing this error. If I comment out all the export * from '...' the command works with no errors. I even selectively commented out some of them, but even the most simplest export of just my permissions.js also trips that error.

@CMCDragonkai
Copy link
Author

This bug is now resolved in 5.3.5.

@mkapiczy
Copy link

I'm having the same issue with version 5.4.0

npm run docs

> [email protected] docs /builds/project-0
> node ./node_modules/.bin/documentation build ./src/services/index.js --output ./docs --format html --config .documentation.yml --github

Error: Parsing file /builds/project-0/src/services/Auth.js: 'import' and 'export' may appear only with 'sourceType: module' (11:0)
    at Deps.parseDeps (/builds/project-0/node_modules/module-deps-sortable/index.js:467:28)
    at fromSource (/builds/project-0/node_modules/module-deps-sortable/index.js:402:44)
    at /builds/project-0/node_modules/module-deps-sortable/index.js:396:17
    at ConcatStream.<anonymous> (/builds/project-0/node_modules/module-deps-sortable/node_modules/concat-stream/index.js:36:43)
    at ConcatStream.emit (events.js:165:20)
    at finishMaybe (/builds/project-0/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:475:14)
    at endWritable (/builds/project-0/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:485:3)
    at ConcatStream.Writable.end (/builds/project-0/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:455:41)
    at DuplexWrapper.onend (/builds/project-0/node_modules/readable-stream/lib/_stream_readable.js:570:10)
    at Object.onceWrapper (events.js:255:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] docs: `node ./node_modules/.bin/documentation build ./src/services/index.js --output ./docs --format html --config .documentation.yml --github`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] docs script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-02-20T12_37_07_578Z-debug.log

What's interesting everything works in my local environment:
OS: OSX
Node: 9.5.0
npm: 5.6.0

But it does not in my docker container in gitlab-ci with the same version of node.
The docker image: https://hub.docker.com/r/mkapiczy/docker-java-node-chrome/

The error occured after webpack upgrade (from version 1 -> 3), but the project build and all tests run fine.

@AndyOGo
Copy link

AndyOGo commented Nov 22, 2020

I have the same error with typescript files.

npm run docs

> [email protected] docs /stylelint-declaration-strict-value
> documentation build src/lib/*.ts --pe ts --re .ts -f md -o API.md

Error: Parsing file /stylelint-declaration-strict-value/src/lib/validation.ts: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
    at Deps.parseDeps (/stylelint-declaration-strict-value/node_modules/module-deps-sortable/index.js:515:28)
    at fromSource (/stylelint-declaration-strict-value/node_modules/module-deps-sortable/index.js:450:44)
    at /stylelint-declaration-strict-value/node_modules/module-deps-sortable/index.js:444:17
    at ConcatStream.<anonymous> (/stylelint-declaration-strict-value/node_modules/module-deps-sortable/node_modules/concat-stream/index.js:36:43)
    at ConcatStream.emit (events.js:203:15)
    at finishMaybe (/stylelint-declaration-strict-value/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:475:14)
    at endWritable (/stylelint-declaration-strict-value/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:485:3)
    at ConcatStream.Writable.end (/stylelint-declaration-strict-value/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:455:41)
    at DuplexWrapper.onend (/stylelint-declaration-strict-value/node_modules/readable-stream/lib/_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:286:20)

@backspaces
Copy link

backspaces commented Jul 28, 2021

** Not a problem with documentation or packages, but with yarn, yarn.lock, and node-modules, see post below **

I just got the dreaded Error: Parsing .. error that this issue is following.

I was using:

    "documentation": "13.2.2",

and upgraded to

    "documentation": "13.2.3",

and ran into

    Error: Parsing file /Users/owen/Dropbox/src/agentscript/src/DataSet.js: 'import' and 'export' may appear only with 'sourceType: module' (1:0)

The documentation command is:

    documentation build src/** --config config/documentation.yml --github --sort-order 'alpha' -f html -o docs

In this case, it appears that commits after 13.2.2 but before 13.2.3 may be revealing:

  https://github.com/documentationjs/documentation/compare/v13.2.2...master

My impression is that it relates to the dependencies, not documentation.js per se.

Oddly enough, when I do a yarn (install) switching back to 13.2.2 I get this message:

warning Pattern ["object-assign@latest"] is trying to unpack in the same destination "/Users/owen/Library/Caches/Yarn/v6/npm-object-assign-4.1.1-2109adc7965887cfc05cbbd442cac8bfbb360863-integrity/node_modules/object-assign" as pattern ["object-assign@","object-assign@","object-assign@*","object-assign@^4.0.1","object-assign@^4.1.0","object-assign@^4.0.1","object-assign@^4.1.1","object-assign@^4"]. This could result in non-deterministic behavior, skipping.
[3/4] 🔗 Linking dependencies...
warning "documentation > @babel/preset-env > @babel/[email protected]" has incorrect peer dependency "@babel/core@^7.13.0".

If it would help, I could create a repo having only documentation.js and the source files, and see if the problem remains. This mainly to minimize interaction with the various other packages.

Here is the entire error stack.

Error: Parsing file /Users/owen/Dropbox/src/agentscript/src/DataSet.js: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
at Deps.parseDeps (/Users/owen/Dropbox/src/agentscript/node_modules/module-deps-sortable/index.js:522:28)
at fromSource (/Users/owen/Dropbox/src/agentscript/node_modules/module-deps-sortable/index.js:451:44)
at /Users/owen/Dropbox/src/agentscript/node_modules/module-deps-sortable/index.js:445:17
at ConcatStream. (/Users/owen/Dropbox/src/agentscript/node_modules/module-deps-sortable/node_modules/concat-stream/index.js:36:43)
at ConcatStream.emit (node:events:390:22)
at finishMaybe (/Users/owen/Dropbox/src/agentscript/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:475:14)
at endWritable (/Users/owen/Dropbox/src/agentscript/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:485:3)
at ConcatStream.Writable.end (/Users/owen/Dropbox/src/agentscript/node_modules/module-deps-sortable/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:455:41)
at DuplexWrapper.onend (/Users/owen/Dropbox/src/agentscript/node_modules/readable-stream/lib/_stream_readable.js:577:10)
at Object.onceWrapper (node:events:484:28)

@backspaces
Copy link

I decided to go ahead and make a separate repo, free of all the dependencies of my repo that failed.

Here's the package.json:

{
    "name": "docbug",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "build": "documentation build src/** --config config/documentation.yml --github --sort-order 'alpha' -f html -o docs"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "devDependencies": {
        "documentation": "^13.2.5"
    }
}

Yarn install works fine, and npm run build creates the docs correctly.

I do get a warning: warning "documentation > @vue/[email protected]" has unmet peer dependency "[email protected]".

The repo is: https://github.com/backspaces/docbug
And the github page is: https://backspaces.github.io/docbug/

Click on Docs to see the resulting documentation.

Sooo .. as we suspected, the difficulty relates to dependencies and their interaction. Here are the dependencies of the original repo:

    "dependencies": {
        "three": "^0.120.0"
    },
    "devDependencies": {
        "@rollup/plugin-commonjs": "^19.0.1",
        "@rollup/plugin-node-resolve": "^13.0.2",
        "@rollup/plugin-url": "^6.0.0",
        "@turf/turf": "^6.5.0",
        "ava": "^2.1.0",
        "chokidar-cli": "^1.2.1",
        "documentation": "13.2.2",
        "esbuild": "^0.12.15",
        "esinstall": "^1.1.7",
        "esm": "^3.2.25",
        "live-server": "latest",
        "npm-run-all": "4.1.2",
        "puppeteer": "*",
        "rollup": "^2.33.1",
        "rollup-plugin-cleanup": "*",
        "rollup-plugin-copy": "*",
        "rollup-plugin-terser": "*",
        "rollup-plugin-url-resolve": "*",
        "shx": "0.3"
    }

On a whim, I put these in the docbug package.json to make sure it would fail So I did that and ran Yarn, then ran the build script .. and it worked!!

WTF? So I removed both node-modules and the yarn.lock and then yarn installed.

Sigh, it then all worked!

** So summary: apparently there was some weird interaction between yarn.lock, package.json and yarn install. Zapping yarn.lock and node-modules, then running yarn somehow fixed things. **

backspaces added a commit to backspaces/agentscript that referenced this issue Jul 29, 2021
- publish next version
- package.json
  - update to latest documentation.js
  - build-docs: alphabetical sort
- documentation
  - lots of jsDoc comments additions/upgrades
  - documentationjs/documentation#950
    Resolve problem with complete wipe of node_modules etc & rebuild.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants