Closed johnelliott closed 1 year ago
Hi, what does your package.json look like? Yes, the runtime will install all child dependencies as well. But one thing to keep in mind is that the entire node_modules folder is ignored during uploading of source code, so your package.json has to contain all of your dependencies and cannot reference any files inside of 'node_modules'. In other words, your functions should still be able to work if you ran the following commands inside of the functions folder:
rm -rf node_modules
npm install
Hello, it looks like the whole package is there in the debug output near the top.
Once the files are built, I think the command you showed here should work. I don’t think I have any private modules or ones unavailable outside npm. I will confirm this once I get back to my computer.
I took a look at my bundle to see if there were any obviously broken require calls, so I’ll have to do a more complete look and update this with more information.
OK, here is my package.json and webpack config for the server code.
I'm still working on finding the source of the problem. It would be easier if I could look at what firebase has installed so I can see what is working and not working, and what version of npm it's running so I can better imitate it locally or something.
package.json:
{
"name": "webpacktest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack-cli",
"buildP": "NODE_ENV=production npm run build",
"build:client": "webpack-cli --config webpack.client.config.js",
"build:server": "webpack-cli --config webpack.server.config.js",
"dev:devserver": "webpack-dev-server --config webpack.client.config.js",
"dev:assets": "webpack-cli --watch --config webpack.server.config.js",
"dev:server": "nodemon --delay 1 --watch dist/server.js --exec node dist/server.js",
"start": "npm run buildP && node dist/server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "John Elliott <johnelliott703@gmail.com> (http://primitivemachine.com/)",
"license": "MIT",
"dependencies": {
"@material/animation": "^0.34.0",
"@material/base": "^0.35.0",
"@material/button": "^0.35.0",
"@material/react-button": "^0.1.0",
"@material/react-material-icon": "^0.1.0",
"@material/react-ripple": "^0.1.0",
"@material/react-top-app-bar": "^0.1.0",
"@material/ripple": "^0.35.0",
"@material/theme": "^0.35.0",
"@material/top-app-bar": "^0.35.2",
"@material/typography": "^0.35.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"compression": "^1.7.2",
"debug": "^3.1.0",
"dotenv": "^5.0.1",
"express": "^4.16.3",
"firebase": "^4.13.1",
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.3",
"morgan": "^1.9.0",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-redux": "^5.0.7",
"react-redux-firebase": "^2.1.0",
"redux": "^4.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"css-loader": "^0.28.11",
"extract-loader": "^2.0.1",
"file-loader": "^1.1.11",
"firebase-tools": "^3.18.4",
"node-sass": "^4.9.0",
"nodemon": "^1.17.3",
"sass-loader": "^7.0.1",
"standard": "^11.0.1",
"style-loader": "^0.21.0",
"webpack": "^4.8.1",
"webpack-cli": "^2.0.15",
"webpack-dev-server": "^3.1.4",
"webpack-node-externals": "^1.7.2"
}
}
Here's my webpack configuration
const serverConfig = {
target: 'node',
externals: [nodeExternals({ whitelist: [/^@material/] })],
mode,
devtool,
entry: { server: path.join(__dirname, 'src/server.js') },
optimization: globalOptimization, // just minify etc.
module: {
rules: [
...globalRules, // just file-loader for static assets
{
test: /\.scss$/,
use: [
{
loader: 'file-loader',
options: {
emit: true,
name: '[name].[hash].css'
}
},
'extract-loader',
'css-loader',
sassLoader
]
},
{
test: /\.js$/,
include: path.join(__dirname, 'node_modules', '@material'), // allow es6 imports from these packages into webpack...
loader: 'babel-loader',
options: {
presets: [
['env', {
debug: true,
targets: { node: 6 } // GCP seems to support this
}],
'react'
],
plugins: [
'transform-class-properties',
'transform-object-rest-spread'
]
}
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
['env', {
debug: true,
targets: { node: 6 }
}],
'react'
]
}
}
]
},
plugins: [
// banner, hot module, named modules, but only for development
...globalPlugins,
...serverPlugins
],
output
}
@johnelliott The Google Cloud Functions runtime uses Node 6, not sure what version of npm. It will only run "npm install", it will not run any build commands. So when you're testing it locally, make sure it works with
rm -rf node_modules
npm install
Closing because it’s probably just my issue. Don’t have time to investigate further. Sorry for the noise.
This is apparently still a real problem
Provided module can't be loaded. Did you list all required modules in the package.json dependencies? Detailed stack trace: Error: Cannot find module '../services/pullPsaCredentials'
pullPsaCredentials isn't even a node module, it's just a part of my program. This all runs fine in the emulator so I have no idea why it wouldn't just work.
I need to deploy this project now so I'm just gonna zip it and ship it. But really this shouldn't be happening, it isn't even an npm node module it's just a file
@johnelliott you aren't alone :D
@johnelliott you aren't alone :D
Ok I spent about 2 days on this pain and figured it out. The issue is ONLY based on the naming. You cannot have camelcase or uppercase file names in the paths. So so so stupid.
So, rename your filenames to lower case (and directories, remove dashes) and change your imports to follow.
After that, all is good.
Wow, it's a party. The machine I did this on is off and unavailable to me right now. Anyone else want to share some similar dumps so we can help the firebase team see if this is something they can help with?
Wow, it's a party. The machine I did this on is off and unavailable to me right now. Anyone else want to share some similar dumps so we can help the firebase team see if this is something they can help with?
Yup, do I went from this:
@my-custom-dependency/common-datasources/dist/fireStoreHelpers
import {
A,
B
} from '@my-custom-dependency/common-datasources/dist/fireStoreHelpers';
to:
@my-custom-dependency/common-datasources/dist/firestorehelpers
import {
A,
B
} from '@my-custom-dependency/common-datasources/dist/firestorehelpers';
I figured it was something with my build systems and all sorts of stuff. But, alas - this was the "issue".
This is happening to me, but with an actual package, in fact it's firebase-tools
Detailed stack trace: Error: Cannot find module 'firebase-tools'
The package is installed and is definitely present in the package and package-lock files
For folks still experiencing this / issues related to this, please go ahead and open new bugs. It's hard to track this due to the age of the bug.
@johnelliott you aren't alone :D
Ok I spent about 2 days on this pain and figured it out. The issue is ONLY based on the naming. You cannot have camelcase or uppercase file names in the paths. So so so stupid.
So, rename your filenames to lower case (and directories, remove dashes) and change your imports to follow.
After that, all is good.
Thank you so much. exactly so stupid error, It has resolved just by renaming my directories to small letters
Thank you @taeold 👍
Version info
firebase-tools 3.18.5 node 8.11.2
Platform Information
OS X / macOS
Steps to reproduce
I have one function called
server
modeled after the sample code here. It's an https function that takes an Express app.I ran
$ firebase deploy --only functions,hosting
.I get errors after/at the end of the deploy seemingly during function start where there are node_modules that are not found.
Expected behavior
Modules should be available in node_modules
Actual behavior
I can't tell by the wording of the docs on dependencies whether the cloud functions servers will install child dependencies in addition to ones listed. It could also be a webpack issue because I am allowing some scss and es6 modules in node_modules to import differently via webpack rules. I am targeting node version 6 in my webpack build for the server code. This is because I reference built css files by their content-dependent hash name for server rendering.
If I manually install the classnames package in this error, I get the same sort of error for another dependency. I think this is just the first one that triggers the error, but presumably there are many.
I would like to know from the maintainers what kind of issue this seems like. Is it me, or perhaps I'm doing something unsupported?
Output I get:
Here's the last bit: ...
....
Entire dump: