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

srcP.startsWith is not a function when adding --up #94

Closed
kokoshneta opened this issue Nov 7, 2020 · 10 comments
Closed

srcP.startsWith is not a function when adding --up #94

kokoshneta opened this issue Nov 7, 2020 · 10 comments

Comments

@kokoshneta
Copy link

kokoshneta commented Nov 7, 2020

I rarely work with Node/NPM and have only just found this package now, so consider me brand new. I’m working on a Windows 2012 R2 Server.

I’ve managed to get node run copyfiles path/to/input/file.ext output/path on its own to work and copy the files as expected. But if I try to go up, regardless of whether I use -u or --up and regardless of how many levels, I get the error that srcP.startsWith is not a function. For example, if I’m in my project folder and do the following:

C:\inetpub\vhosts\project> node run copyfiles -u 4 node_modules/library/input/path/css/*.css dist/styles

– then I get the following error message:

> mypackage@1.0.0 copyfiles C:\inetpub\vhosts\project
> copyfiles "4" "node_modules/library/input/path/css/*.css" "styles"

C:\inetpub\vhosts\project\node_modules\copyfiles\index.js:94
toStream(input.map(function(srcP) {return srcP.startsWith('~') ? untildify(srcP) : srcP;}))
					       ^
TypeError: srcP.startsWith is not a function
	at C:\inetpub\vhosts\project\node_modules\copyfiles\index.js:94:50
	at Array.map (<anonymous>)
	at copyFiles (C:\inetpub\vhosts\project\node_modules\copyfiles\index.js:94:18)
	at Object.<anonymous> (C:\inetpub\vhosts\project\node_modules\copyfiles\copyfiles:40:1)
	at Module._compile (internal/modules/cjs/loader.js:701:30)
	at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
	at Module.load (internal/modules/cjs/loader.js:600:32)
	at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
	at Function.Module._load (internal/modules/cjs/loader.js:531:3)
	at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)

At first blush, that looks to me like it’s treating the number 4 as a file name (the -u having apparently disappeared?) but recognising it’s an integer, converts it, and then logically enough cannot find startsWith(), which is a string function.

But is that right? And if so, why? I must be missing some step in getting this to work, but I have no idea which, or where…

@calvinmetcalf
Copy link
Owner

calvinmetcalf commented Nov 7, 2020 via email

@calvinmetcalf
Copy link
Owner

just quckly, are you actually running it with node run copyfiles ... im not familiar with that syntax, you should just be able to do copyfiles path/to/input/file.ext output/path if you installed it globally or npx copyfiles path/to/input/file.ext output/path if you didn't

@kokoshneta
Copy link
Author

kokoshneta commented Nov 9, 2020

I’m running with npm run (Edit: Sorry, just noticed: node was a typo in the original comment – should have been npm). I tried just copyfiles on its own, which gave me the standard (PowerShell) ‘command not recognised’ error, even though I think I did install it globally. Not sure offhand if I removed the global copy before installing the local copy, though.

Will try with npx when I’m back at my computer and report back.

@calvinmetcalf
Copy link
Owner

ok so what does the copyfiles script in your package.json look like?

@kokoshneta
Copy link
Author

Just tried with NPX which failed too. Apart from some notifications telling me things like Found & ignored ./node_modules ; is listed in .gitignore, it gave me this:

Starting: copyfiles --up 1 node_modules/@fortawesome/fontawesome-pro/css/*.css ../styles/fa
internal/modules/cjs/loader.js:584
	throw err;
	^

Error: Cannot find module 'C:\inetpub\vhosts\project\copyfiles'
	at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
	at Function.Module._load (internal/modules/cjs/loader.js:508:25)
	at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
	at startup (internal/bootstrap/node.js:283:19)
	at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Note the incorrect path looking for copyfiles directly in the project folder instead of the node_modules folder. This may well just be something to do with my NPX setup, though – I did set it up for something ages ago, but I don’t remember how or for what, and I never actively use it.

As for my package.json, this is it in its entirety:

{
	"private": true,
	"name": "project",
	"version": "0.0.1",
	"scripts": {
		"postinstall": "npm run copyfiles css/*.css webfonts ./../styles/fa",
		"copyfiles": "copyfiles"
	},
	"dependencies": {
		"postinstall": "*",
		"copyfiles": "latest",
		"@fortawesome/fontawesome-pro": "latest"
	}
}

(As you may have surmised, I’m primarily wanting to use copyfiles to automatically copy CSS and webfont files over to the right folders whenever I update Font Awesome through NPM.)

@calvinmetcalf
Copy link
Owner

calvinmetcalf commented Nov 9, 2020 via email

@kokoshneta
Copy link
Author

Ah, I hadn’t actually tried that yet – I wanted to make sure I had the parameters right in the command line first before ‘committing’ it to automation. I’ll try adding it and see if that might work.

@kokoshneta
Copy link
Author

So I modified the package.json file like this:

"scripts": {
	"postinstall": "npm run copyfiles -u 3 node_modules/@fortawesome/fontawesome-pro/css/*.css node_modules/@fortawesome/fontawesome-pro/webfonts ./../styles/fa",
	"copyfiles": "copyfiles"
}

Doing npm run postinstall now executes the copyfiles call, but still with the same error:

> project@0.0.1 postinstall C:\inetpub\vhosts\project\
> npm run copyfiles -u 3 node_modules/@fortawesome/fontawesome-pro/css/*.css node_modules/@fortawesome/fontawesome-pro/webfonts ./../styles/fa

> project@0.0.1 copyfiles C:\inetpub\vhosts\project\
> copyfiles "3" "node_modules/@fortawesome/fontawesome-pro/css/*.css" "node_modules/@fortawesome/fontawesome-pro/webfonts" "./../styles/fa"

C:\inetpub\vhosts\project\node_modules\copyfiles\index.js:94
toStream(input.map(function(srcP) {return srcP.startsWith('~') ? untildify(srcP) : srcP;}))
					       ^

TypeError: srcP.startsWith is not a function
	at C:\inetpub\vhosts\project\node_modules\copyfiles\index.js:94:50
	at Array.map (<anonymous>)
	at copyFiles (C:\inetpub\vhosts\project\node_modules\copyfiles\index.js:94:18)
	at Object.<anonymous> (C:\inetpub\vhosts\project\node_modules\copyfiles\copyfiles:40:1)
	at Module._compile (internal/modules/cjs/loader.js:701:30)
	at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
	at Module.load (internal/modules/cjs/loader.js:600:32)
	at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
	at Function.Module._load (internal/modules/cjs/loader.js:531:3)
	at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project@0.0.1 copyfiles: `copyfiles "3" "node_modules/@fortawesome/fontawesome-pro/css/*.css" "node_modules/@fortawesome/fontawesome-pro/webfonts" "./../styles/fa"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project@0.0.1 copyfiles 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!     C:\Users\XXX\AppData\Roaming\npm-cache\_logs\2020-11-09T22_10_33_526Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project@0.0.1 postinstall: `npm run copyfiles -u 3 node_modules/@fortawesome/fontawesome-pro/css/*.css node_modules/@fortawesome/fontawesome-pro/webfonts ./../styles/fa`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project@0.0.1 postinstall 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!     C:\Users\XXX\AppData\Roaming\npm-cache\_logs\2020-11-09T22_10_33_606Z-debug.log

The two error logs noted don’t tell me an awful lot more offhand, but they probably give you more info than me, so they’re attached here: log-606Z.log, log-526Z.log.

@calvinmetcalf
Copy link
Owner

"postinstall": "npm run copyfiles css/*.css webfonts ./../styles/fa",

change that to

"postinstall": "copyfiles css/*.css webfonts ./../styles/fa",

npm automatically puts scripts into the path when you run it like that

@kokoshneta
Copy link
Author

That did it! Had to change the second input to webfonts/*.* for it to actually grab the folder and containing files (I suppose it just looked for a file named webfonts rather than a directory?), but then it worked exactly as I wanted. Thank you so much for all your help!

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

2 participants